# subset

> Generalized set operations and comparisons in the style of Haskell

Latest version **1.1.0** (published 2016-01-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install subset
pnpm add subset
yarn add subset
bun add subset
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2016-01-28 |
| First published | 2012-06-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Eirik Albrigtsen |
| Maintainers | clux |
| Keywords | compare, comparing, equality, union, intersect, nub, group, generalized, haskell, Data.List, Ord, ES6 |

## Links

- npm: https://www.npmjs.com/package/subset
- Repository: https://github.com/clux/subset
- Homepage: https://github.com/clux/subset#readme
- Issues: https://github.com/clux/subset/issues
- npm.io page: https://npm.io/package/subset

## Recent versions

- 1.1.0 (latest) — 2016-01-28
- 1.0.0 — 2016-01-27
- 0.1.7 — 2015-11-14
- 0.1.6 — 2014-09-02
- 0.1.5 — 2014-07-10
- 0.1.4 — 2013-04-26
- 0.1.3 — 2012-11-11
- 0.1.2 — 2012-10-24
- 0.1.1 — 2012-09-20
- 0.1.0 — 2012-06-16

## README

# Subset
[![npm status](http://img.shields.io/npm/v/subset.svg)](https://www.npmjs.org/package/subset)
[![build status](https://secure.travis-ci.org/clux/subset.svg)](http://travis-ci.org/clux/subset)
[![dependency status](https://david-dm.org/clux/subset.svg)](https://david-dm.org/clux/subset)
[![coverage status](http://img.shields.io/coveralls/clux/subset.svg)](https://coveralls.io/r/clux/subset)

Subset provides basic and generalized set operations for JavaScript.
They are inspired by a subset of the interface to Haskell's [Data.List](https://hackage.haskell.org/package/base/docs/Data-List.html), but optimized for JavaScript semantics.

The new ES6 `Set` class is not particularly helpful for doing set operations on general objects (as their only version of equality is `===`), and this module provides a general alternative for people who want to do the same-ish things on arrays.

## Usage
Use it with qualified imports with the yet unfinished module `import` syntax or attach it to the short variable of choice. For selling points, here's how it will look with ES7 modules.

```js
import { equality, union, unionBy, intersect, unique, uniqueBy, insert, delete, group } from 'autonomy'

intersect([1,2,3,4], [2,4,6,8]); // [ 2, 4 ]

union([1,3,5], [4,5,6]); // [ 1, 3, 5, 4, 6 ]
unionBy(equality('a'), [{ a: 1 }, { a: 3 }], [{ a: 2 }, { a: 3 }]);
// [ { a: 1 }, { a: 3 }, { a: 2 } ]

unique([1,3,2,4,1,2]); // [ 1, 3, 2, 4 ]

var notCoprime = (x, y) => gcd(x, y) > 1;
var primes = uniqueBy(notCoprime, [2,3,4,5,6,7,8,9,10,11,12]); // [ 2, 3, 5, 7, 11 ]

group([1,2,2,3,5,5,2]); // [ [1], [2,2], [3], [5,5], [2] ]

insert([1,2,3,4], 3); // [ 1, 2, 3, 3, 4 ]

delete([1,2,3,2,3], 2); // [ 1, 3, 2, 3 ]
```

Read the [full API](https://github.com/clux/subset/blob/master/api.md).

Note that it is often useful to get it with the larger utility library [interlude](https://github.com/clux/interlude) for which it was made.

## License
MIT-Licensed. See LICENSE file for details.

---
_Source: https://npm.io/package/subset · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
