# naif

> A naive set library.

Latest version **0.0.7** (published 2014-05-21) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.7 |
| Published | 2014-05-21 |
| First published | 2014-03-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | asciiascetic@gmail.com |
| Maintainers | asciiascetic |
| Keywords | sets, aspic |

## Links

- npm: https://www.npmjs.com/package/naif
- Repository: https://github.com/asciiascetic/naif
- Issues: https://github.com/asciiascetic/naif/issues
- npm.io page: https://npm.io/package/naif

## Dependencies (1)

- [aspic](https://npm.io/package/aspic.md) >= 0.0.4

## Recent versions

- 0.0.7 (latest) — 2014-05-21
- 0.0.6 — 2014-04-10
- 0.0.4 — 2014-04-01
- 0.0.3 — 2014-03-31
- 0.0.2 — 2014-03-29
- 0.0.1 — 2014-03-29

## README

naif
====

Naive sets.

The sets are limited in what they can store b/c are based on
[aspic](https://www.npmjs.org/package/aspic). Anything that is not
serializable by JSON.stringify cannot be stored.

example usage
-------------

    var naif = require('naif');
	
	// call the naif function with zero or more array arguments:
	
	var e = naif();
	
	e.empty(); //true
	
	var s1 = naif(['hello','there', 'this'],['is', 'is', 'is', 'a', 'set']);
	
	s1.size();  //6
	
	var s2 = naif(['hello','again'],['one',2, 3.1415, {'six' : 7}]);
	
	s2.size(); //6
	
	// we can do set operations using logical language:
	
	var s1_intersect_s2 = s1.and(s2);
	
	s1_intersect_s2.size();   //1

	s1_intersect_s2.each(console.log);
	
	// hello
	
	// we can chain several operators.
	// the following prints out each string that is in the union of s1 and s2
	
	s1.or(s2).suchthat(function(e) {return e.constructor === String}).each(console.log);
	
	// hello
	// there
	// this
	// is
	// a
	// set
	// again
	// one


api
---

### naif()

The `naif(array*)` function takes zero or more arrays and returns a set object;

### set objects

Given a set called `s`, the following functions are supported:

- `s.size()` : returns the number of elements in the set

- `s.each(fn)` : the basic set iterator, where `fn` is a function of a
  single argument.

- `s.or(s2)` : returns the union of `s` and `s2`, where both are sets
  returned by `naif`

- `s.and(s2)` : returns the intersection of `s` and `s2`

- `s.not(s2)` : returns the set difference, `s` less `s2`

- `s.xor(s2)` : returns those elements in `s` or `s2` but not in both

- `s.empty()` : returns `true` if `s` is the empty set

- `s.all(p)` : returns `true` if `p(e)` is true for each `e` in `s`

- `s.exists(p)` : returns `true` if `p(e)` is true for at least one `e` in `s`

- `s.subset(s2)` : returns `true` if `s` is a subset of `s2`

- `s.superset(s2)` : returns `true` if `s` is a superset of `s2`

- `s.equal(s2)` : returns `true` if `s` and `s2` contain the same
  elements, up to the equality of their serialized contents (see
  [aspic](https://www.npmjs.org/package/aspic) for details about
  serialization)

- `s.toArray()` : returns an array of the set's contents.
  
- `s.mutable()` : this extends `s` with new methods for mutability,
  returning a new *mutable set* that shares memory with `s`.
  

### mutable set objects

Mutable sets have all of the functions above, plus two more:

- `ms.insert(x)` : inserts `x` into the the set
- `ms.remove(x)` : removes `x` from the set

oh goodie.

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