1.0.0 • Published 6 years ago

nonempty-collections v1.0.0

Weekly downloads
3
License
ISC
Repository
github
Last release
6 years ago

nonempty-collections

A type NonEmptyArray that inherits from JavaScript's Array type and guarantees that it always has at least one item. A type NonEmptySet that inherits from JavaScript's Set type and guarantees that it always has at least one item.

Usage:

const { NonEmptyArray, NonEmptySet } = require("nonempty-collections");

myArray = NonEmptyArray(1, 2, 3);
mySet = NonEmptyset(1, 2, 3);

The APIs are the same as those of Array and Set respectively; where appropriate, they return an object of their own type rather than the base type. Any operation that would empty the container will instead throw a TypeError.