Set

GitHub   Edit on GitHub

A Set is an unordered collection of unique values. Operations on a Set mutate the internal state, so it never needs to be re-assigned.

1
import Set from "set"

Values

Set.make

1
make : () -> Set<t>

Creates a new, empty set.

Set.makeSized

1
makeSized : Number -> Set<t>

Creates a new, empty set with an initial storage size for the given number of elements.

Set.add

1
add : (t, Set<t>) -> Void

Adds a new value to the set. If the value already exists, nothing happens.

Set.contains

1
contains : (t, Set<t>) -> Bool

Returns true if the set contains the given value.

Set.remove

1
remove : (t, Set<t>) -> Void

Removes the given value from the set.

Set.size

1
size : Set<t> -> Number

Returns the number of values within the set.

Set.isEmpty

1
isEmpty : Set<t> -> Number

Returns true if the set contains no values.

Set.clear

1
clear : Set<t> -> Void

Removes all values from the set.

Set.forEach

1
forEach : ((t) -> Void, Set<t>) -> Void

Iterates the given function over each value in the set.

Set.reduce

1
reduce : ((a, t) -> a, a, Set<t>) -> a

Reduces all values within a set to a single value. The reducer function is called with the accumulator and the current value.

Set.toList

1
toList : Set<t> -> List<t>

Returns a list from the values of a set.

Set.fromList

1
fromList : List<t> -> Set<t>

Creates a set from a list.

Set.toArray

1
toArray : Set<t> -> Array<t>

Returns an array from the values of a set.

Set.fromArray

1
fromArray : Array<t> -> Set<t>

Creates a set from an array.

Set.filter

1
filter : ((t) -> Bool, Set<t>) -> Void

Keeps all values that the predicate returned true for from the set.

Set.reject

1
reject : ((t) -> Bool, Set<t>) -> Void

Removes all values that the predicate returned true for from the set.

Set.union

1
union : (Set<t>, Set<t>) -> Set<t>

Creates a set from the union of the given sets.

Set.intersect

1
intersect : (Set<t>, Set<t>) -> Set<t>

Creates a set from the intersection of the given sets.

Set.diff

1
diff : (Set<t>, Set<t>) -> Set<t>

Creates a set from the difference of the given sets.

This is a notification!