Skip to content

Latest commit

 

History

History
248 lines (170 loc) · 3.88 KB

File metadata and controls

248 lines (170 loc) · 3.88 KB

Module iiris/set

The iiris/set module includes functions for working with Sets. It is designed to be imported with a wildcard, e.g.

import * as S from 'iiris/array'

Table of contents

Basic set operations

add

<T>(value: T) => (set: Set<T>) => Set<T>

Return a copy of set with value.

  • If set already contains value, it is returned unchanged.
Example
S.add(4, S.from([1, 2, 3]))
// => Set(4) { 1, 2, 3, 4 }

See also: add, has


remove

<T>(value: T) => (set: Set<T>) => Set<T>

Return a copy of set without value.

  • If set doesn't contain value, it is returned unchanged.
Example
S.remove(1, S.from([1, 2, 3]))
// => Set(2) { 2, 3 }

See also: add, has


Creating sets

empty

<T>() => Set<T>

Create an empty set.

Example
S.empty()
// => Set(0) {}

See also: from, singleton


from

<T>(iterable: Iterable<T>) => Set<T>

Convert an iterable into a set.

Example
S.from([1, 2, 3])
// => Set(3) { 1, 2, 3 }

See also: empty, singleton


singleton

<T>(value: T) => Set<T>

Create a singleton set containing value.

Example
S.singleton(1)
// => Set(1) { 1 }

See also: empty, from


Other

has

<T>(value: T) => (set: Set<T>) => boolean

Check if set contains value.

Example
S.has(1, S.from([1, 2, 3]))
// => true

isEmpty

<T>(set: Set<T>) => boolean

Check if the set is empty.

Example
S.isEmpty(S.empty())
// => true

Set operations

difference

<T>(first: Set<T>) => (second: Set<T>) => Set<T>

Calculate the difference between two sets.

Example
S.difference(S.from([1, 2, 3]), S.from([2, 3, 4]))
// => Set(4) { 1 }

See also: intersection, union


intersection

<T>(first: Set<T>) => (second: Set<T>) => Set<T>

Calculate the intersection between two sets.

Example
S.intersection(S.from([1, 2, 3]), S.from([2, 3, 4]))
// => Set(4) { 2, 3 }

See also: intersection, union


union

<T>(first: Set<T>) => (second: Set<T>) => Set<T>

Calculate the union between two sets.

Example
S.union(S.from([1, 2, 3]), S.from([2, 3, 4]))
// => Set(4) { 1, 2, 3, 4 }

See also: difference, intersection