Set
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.
Edit on GitHubAn immutable set implementation is available in the Immutable submodule.
Added in 0.3.0
No other changes yet.
from "set" include Set
Type declarations included in the Set module.
type Set<k>
record InternalSetStats {
currentSize: Number,
bucketCount: Number,
}
Represents the internal state of a set.
Functions and constants included in the Set module.
Added in 0.3.0
| version | changes |
|---|---|
0.6.0 | Merged with `makeSized`; modified signature to accept size |
make : (?size: Number) => Set<a>
Creates a new empty set with an initial storage of the given size. As values are added or removed, the internal storage may grow or shrink. Generally, you won’t need to care about the storage size of your set and can use the default size.
Parameters:
| param | type | description |
|---|---|---|
?size | Number | The initial storage size of the set |
?size: The initial storage size of the setReturns:
| type | description |
|---|---|
Set<a> | An empty set with the given initial storage size |
Set<a>: An empty set with the given initial storage sizeAdded in 0.3.0
No other changes yet.
add : (key: a, set: Set<a>) => Void
Adds a new value to the set. If the value already exists, nothing happens.
Parameters:
| param | type | description |
|---|---|---|
key | a | The value to add |
set | Set<a> | The set to update |
key: The value to addset: The set to updateAdded in 0.3.0
No other changes yet.
contains : (key: a, set: Set<a>) => Bool
Determines if the set contains the given value.
Parameters:
| param | type | description |
|---|---|---|
key | a | The value to search for |
set | Set<a> | The set to search |
key: The value to search forset: The set to searchReturns:
| type | description |
|---|---|
Bool | true if the set contains the given value or false otherwise |
Bool: true if the set contains the given value or false otherwiseAdded in 0.3.0
No other changes yet.
remove : (key: a, set: Set<a>) => Void
Removes the given value from the set. If the value doesn’t exist, nothing happens.
Parameters:
| param | type | description |
|---|---|---|
key | a | The value to remove |
set | Set<a> | The set to update |
key: The value to removeset: The set to updateAdded in 0.3.0
No other changes yet.
size : (set: Set<a>) => Number
Provides the count of values within the set.
Parameters:
| param | type | description |
|---|---|---|
set | Set<a> | The set to inspect |
set: The set to inspectReturns:
| type | description |
|---|---|
Number | The count of elements in the set |
Number: The count of elements in the setAdded in 0.3.0
No other changes yet.
isEmpty : (set: Set<a>) => Bool
Determines if the set contains no elements.
Parameters:
| param | type | description |
|---|---|---|
set | Set<a> | The set to inspect |
set: The set to inspectReturns:
| type | description |
|---|---|
Bool | true if the given set is empty or false otherwise |
Bool: true if the given set is empty or false otherwiseAdded in 0.3.0
No other changes yet.
clear : (set: Set<a>) => Void
Resets the set by removing all values.
Parameters:
| param | type | description |
|---|---|---|
set | Set<a> | The set to reset |
set: The set to resetAdded in 0.3.0
| version | changes |
|---|---|
0.5.0 | Ensured the iterator function return type is always `Void` |
forEach : (fn: (a => Void), set: Set<a>) => Void
Iterates the set, calling an iterator function on each element.
Parameters:
| param | type | description |
|---|---|---|
fn | a => Void | The iterator function to call with each element |
set | Set<a> | The set to iterate |
fn: The iterator function to call with each elementset: The set to iterateAdded in 0.3.0
No other changes yet.
reduce : (fn: ((a, b) => a), init: a, set: Set<b>) => a
Combines all elements of a set using a reducer function.
Parameters:
| param | type | description |
|---|---|---|
fn | (a, b) => a | The reducer function to call on each element, where the value returned will be the next accumulator value |
init | a | The initial value to use for the accumulator on the first iteration |
set | Set<b> | The set to iterate |
fn: The reducer function to call on each element, where the value returned will be the next accumulator valueinit: The initial value to use for the accumulator on the first iterationset: The set to iterateReturns:
| type | description |
|---|---|
a | The final accumulator returned from fn |
a: The final accumulator returned from fnAdded in 0.3.0
No other changes yet.
filter : (fn: (a => Bool), set: Set<a>) => Void
Removes elements from a set where a predicate function returns false.
Parameters:
| param | type | description |
|---|---|---|
fn | a => Bool | The predicate function to indicate which elements to remove from the set, where returning false indicates the value should be removed |
set | Set<a> | The set to iterate |
fn: The predicate function to indicate which elements to remove from the set, where returning false indicates the value should be removedset: The set to iterateAdded in 0.3.0
No other changes yet.
reject : (fn: (a => Bool), set: Set<a>) => Void
Removes elements from a set where a predicate function returns true.
Parameters:
| param | type | description |
|---|---|---|
fn | a => Bool | The predicate function to indicate which elements to remove from the set, where returning true indicates the value should be removed |
set | Set<a> | The set to iterate |
fn: The predicate function to indicate which elements to remove from the set, where returning true indicates the value should be removedset: The set to iterateAdded in 0.3.0
No other changes yet.
toList : (set: Set<a>) => List<a>
Converts a set into a list of its elements.
Parameters:
| param | type | description |
|---|---|---|
set | Set<a> | The set to convert |
set: The set to convertReturns:
| type | description |
|---|---|
List<a> | A list containing all set values |
List<a>: A list containing all set valuesAdded in 0.3.0
No other changes yet.
fromList : (list: List<a>) => Set<a>
Creates a set from a list.
Parameters:
| param | type | description |
|---|---|---|
list | List<a> | The list to convert |
list: The list to convertReturns:
| type | description |
|---|---|
Set<a> | A set containing all list values |
Set<a>: A set containing all list valuesAdded in 0.3.0
No other changes yet.
toArray : (set: Set<a>) => Array<a>
Converts a set into an array of its elements.
Parameters:
| param | type | description |
|---|---|---|
set | Set<a> | The set to convert |
set: The set to convertReturns:
| type | description |
|---|---|
Array<a> | An array containing all set values |
Array<a>: An array containing all set valuesAdded in 0.3.0
No other changes yet.
fromArray : (array: Array<a>) => Set<a>
Creates a set from an array.
Parameters:
| param | type | description |
|---|---|---|
array | Array<a> | The array to convert |
array: The array to convertReturns:
| type | description |
|---|---|
Set<a> | A set containing all array values |
Set<a>: A set containing all array valuesAdded in 0.3.0
No other changes yet.
union : (set1: Set<a>, set2: Set<a>) => Set<a>
Combines two sets into a single set containing all elements from both sets.
Parameters:
| param | type | description |
|---|---|---|
set1 | Set<a> | The first set to combine |
set2 | Set<a> | The second set to combine |
set1: The first set to combineset2: The second set to combineReturns:
| type | description |
|---|---|
Set<a> | A set containing all elements of both sets |
Set<a>: A set containing all elements of both setsAdded in 0.3.0
No other changes yet.
diff : (set1: Set<a>, set2: Set<a>) => Set<a>
Combines two sets into a single set containing only the elements not shared between both sets.
Parameters:
| param | type | description |
|---|---|---|
set1 | Set<a> | The first set to combine |
set2 | Set<a> | The second set to combine |
set1: The first set to combineset2: The second set to combineReturns:
| type | description |
|---|---|
Set<a> | A set containing only unshared elements from both sets |
Set<a>: A set containing only unshared elements from both setsAdded in 0.3.0
No other changes yet.
intersect : (set1: Set<a>, set2: Set<a>) => Set<a>
Combines two sets into a single set containing only the elements shared between both sets.
Parameters:
| param | type | description |
|---|---|---|
set1 | Set<a> | The first set to combine |
set2 | Set<a> | The second set to combine |
set1: The first set to combineset2: The second set to combineReturns:
| type | description |
|---|---|
Set<a> | A set containing only shared elements from both sets |
Set<a>: A set containing only shared elements from both setsAdded in 0.3.0
| version | changes |
|---|---|
0.6.0 | Return `InternalSetStats` record instead of a tuple |
getInternalStats : (set: Set<a>) => InternalSetStats
Provides data representing the internal state state of the set.
Parameters:
| param | type | description |
|---|---|---|
set | Set<a> | The set to inspect |
set: The set to inspectReturns:
| type | description |
|---|---|
InternalSetStats | The internal state of the set |
InternalSetStats: The internal state of the setAn immutable set implementation.
Added in 0.6.0
| version | changes |
|---|---|
0.5.4 | Originally in `"immutableset"` module |
Type declarations included in the Set.Immutable module.
type Set<a>
Functions and constants included in the Set.Immutable module.
Added in 0.6.0
| version | changes |
|---|---|
0.5.4 | Originally in `"immutableset"` module |
empty : Set<a>
An empty set
Added in 0.6.0
| version | changes |
|---|---|
0.5.4 | Originally in `"immutableset"` module |
size : (set: Set<a>) => Number
Provides the count of values within the set.
Parameters:
| param | type | description |
|---|---|---|
set | Set<a> | The set to inspect |
set: The set to inspectReturns:
| type | description |
|---|---|
Number | The count of elements in the set |
Number: The count of elements in the setAdded in 0.6.0
| version | changes |
|---|---|
0.5.4 | Originally in `"immutableset"` module |
isEmpty : (set: Set<a>) => Bool
Determines if the set contains no elements.
Parameters:
| param | type | description |
|---|---|---|
set | Set<a> | The set to inspect |
set: The set to inspectReturns:
| type | description |
|---|---|
Bool | true if the given set is empty or false otherwise |
Bool: true if the given set is empty or false otherwiseAdded in 0.6.0
| version | changes |
|---|---|
0.5.4 | Originally in `"immutableset"` module |
add : (key: a, set: Set<a>) => Set<a>
Produces a new set by inserting the given value into the set. If the value already exists, the new set will have the same elements as the input set.
Parameters:
| param | type | description |
|---|---|---|
key | a | The value to add |
set | Set<a> | The base set |
key: The value to addset: The base setReturns:
| type | description |
|---|---|
Set<a> | A new set containing the new element |
Set<a>: A new set containing the new elementAdded in 0.6.0
| version | changes |
|---|---|
0.5.4 | Originally in `"immutableset"` module |
contains : (key: a, set: Set<a>) => Bool
Determines if the set contains the given value.
Parameters:
| param | type | description |
|---|---|---|
key | a | The value to search for |
set | Set<a> | The set to search |
key: The value to search forset: The set to searchReturns:
| type | description |
|---|---|
Bool | true if the set contains the given value or false otherwise |
Bool: true if the set contains the given value or false otherwiseAdded in 0.6.0
| version | changes |
|---|---|
0.5.4 | Originally in `"immutableset"` module |
remove : (key: a, set: Set<a>) => Set<a>
Produces a new set without the given element. If the value doesn’t exist in the set, the set will be returned unmodified.
Parameters:
| param | type | description |
|---|---|---|
key | a | The value to exclude |
set | Set<a> | The set to exclude from |
key: The value to excludeset: The set to exclude fromReturns:
| type | description |
|---|---|
Set<a> | A new set without the excluded element |
Set<a>: A new set without the excluded elementAdded in 0.6.0
| version | changes |
|---|---|
0.5.4 | Originally in `"immutableset"` module |
forEach : (fn: (a => Void), set: Set<a>) => Void
Iterates the set, calling an iterator function on each element.
Parameters:
| param | type | description |
|---|---|---|
fn | a => Void | The iterator function to call with each element |
set | Set<a> | The set to iterate |
fn: The iterator function to call with each elementset: The set to iterateAdded in 0.6.0
| version | changes |
|---|---|
0.5.4 | Originally in `"immutableset"` module |
reduce : (fn: ((a, b) => a), init: a, set: Set<b>) => a
Combines all elements of a set using a reducer function.
Parameters:
| param | type | description |
|---|---|---|
fn | (a, b) => a | The reducer function to call on each element, where the value returned will be the next accumulator value |
init | a | The initial value to use for the accumulator on the first iteration |
set | Set<b> | The set to iterate |
fn: The reducer function to call on each element, where the value returned will be the next accumulator valueinit: The initial value to use for the accumulator on the first iterationset: The set to iterateReturns:
| type | description |
|---|---|
a | The final accumulator returned from fn |
a: The final accumulator returned from fnAdded in 0.6.0
| version | changes |
|---|---|
0.5.4 | Originally in `"immutableset"` module |
filter : (fn: (a => Bool), set: Set<a>) => Set<a>
Produces a new set without the elements from the input set where a predicate function returns false.
Parameters:
| param | type | description |
|---|---|---|
fn | a => Bool | The predicate function to indicate which elements to exclude from the set, where returning false indicates the value should be excluded |
set | Set<a> | The set to iterate |
fn: The predicate function to indicate which elements to exclude from the set, where returning false indicates the value should be excludedset: The set to iterateReturns:
| type | description |
|---|---|
Set<a> | A new set excluding the elements not fulfilling the predicate |
Set<a>: A new set excluding the elements not fulfilling the predicateAdded in 0.6.0
| version | changes |
|---|---|
0.5.4 | Originally in `"immutableset"` module |
reject : (fn: (a => Bool), set: Set<a>) => Set<a>
Produces a new set without the elements from the input set where a predicate function returns true.
Parameters:
| param | type | description |
|---|---|---|
fn | a => Bool | The predicate function to indicate which elements to exclude from the set, where returning true indicates the value should be excluded |
set | Set<a> | The set to iterate |
fn: The predicate function to indicate which elements to exclude from the set, where returning true indicates the value should be excludedset: The set to iterateReturns:
| type | description |
|---|---|
Set<a> | A new set excluding the elements fulfilling the predicate |
Set<a>: A new set excluding the elements fulfilling the predicateAdded in 0.6.0
| version | changes |
|---|---|
0.5.4 | Originally in `"immutableset"` module |
union : (set1: Set<a>, set2: Set<a>) => Set<a>
Combines two sets into a single set containing all elements from both sets.
Parameters:
| param | type | description |
|---|---|---|
set1 | Set<a> | The first set to combine |
set2 | Set<a> | The second set to combine |
set1: The first set to combineset2: The second set to combineReturns:
| type | description |
|---|---|
Set<a> | A set containing all elements of both sets |
Set<a>: A set containing all elements of both setsAdded in 0.6.0
| version | changes |
|---|---|
0.5.4 | Originally in `"immutableset"` module |
diff : (set1: Set<a>, set2: Set<a>) => Set<a>
Combines two sets into a single set containing only the elements not shared between both sets.
Parameters:
| param | type | description |
|---|---|---|
set1 | Set<a> | The first set to combine |
set2 | Set<a> | The second set to combine |
set1: The first set to combineset2: The second set to combineReturns:
| type | description |
|---|---|
Set<a> | A set containing only unshared elements from both sets |
Set<a>: A set containing only unshared elements from both setsAdded in 0.6.0
| version | changes |
|---|---|
0.5.4 | Originally in `"immutableset"` module |
intersect : (set1: Set<a>, set2: Set<a>) => Set<a>
Combines two sets into a single set containing only the elements shared between both sets.
Parameters:
| param | type | description |
|---|---|---|
set1 | Set<a> | The first set to combine |
set2 | Set<a> | The second set to combine |
set1: The first set to combineset2: The second set to combineReturns:
| type | description |
|---|---|
Set<a> | A set containing only shared elements from both sets |
Set<a>: A set containing only shared elements from both setsAdded in 0.6.0
| version | changes |
|---|---|
0.5.4 | Originally in `"immutableset"` module |
fromList : (list: List<a>) => Set<a>
Creates a set from a list.
Parameters:
| param | type | description |
|---|---|---|
list | List<a> | The list to convert |
list: The list to convertReturns:
| type | description |
|---|---|
Set<a> | A set containing all list values |
Set<a>: A set containing all list valuesAdded in 0.6.0
| version | changes |
|---|---|
0.5.4 | Originally in `"immutableset"` module |
toList : (set: Set<a>) => List<a>
Converts a set into a list of its elements.
Parameters:
| param | type | description |
|---|---|---|
set | Set<a> | The set to convert |
set: The set to convertReturns:
| type | description |
|---|---|
List<a> | A list containing all set values |
List<a>: A list containing all set valuesAdded in 0.6.0
| version | changes |
|---|---|
0.5.4 | Originally in `"immutableset"` module |
fromArray : (array: Array<a>) => Set<a>
Creates a set from an array.
Parameters:
| param | type | description |
|---|---|---|
array | Array<a> | The array to convert |
array: The array to convertReturns:
| type | description |
|---|---|
Set<a> | A set containing all array values |
Set<a>: A set containing all array valuesAdded in 0.6.0
| version | changes |
|---|---|
0.5.4 | Originally in `"immutableset"` module |
toArray : (set: Set<a>) => Array<a>
Converts a set into an array of its elements.
Parameters:
| param | type | description |
|---|---|---|
set | Set<a> | The set to convert |
set: The set to convertReturns:
| type | description |
|---|---|
Array<a> | An array containing all set values |
Array<a>: An array containing all set values