Module Relude_Set

type t('value, 'id) = Belt.Set.t('value'id);
let empty: (module Belt.Id.Comparable with type identity = 'id and type t = 'value) => Belt.Set.t('value'id);

Set.empty constructs a new, empty set given an identity module.

let fromArray: (module Belt.Id.Comparable with type identity = 'id and type t = 'value) => array('value) => Belt.Set.t('value'id);

Set.fromArray converts an array of values into a new set of those values, ordered by the comparator function from the provided Comparable module.

let fromList: (module Belt.Id.Comparable with type identity = 'id and type t = 'value) => list('value) => Belt.Set.t('value'id);

Set.fromList converts a list of values into a new set of those values, ordered by the comparator function Comparable.cmp.

let isEmpty: t('value'id) => bool;

Determine whether a set is empty.

let contains: 'value => t('value'id) => bool;

Determine whether a set contains a given value.

let add: 'value => t('value'id) => t('value'id);

Immutably add a value to a set. If the value already exists in the set, the original set (physical reference) is returned unchanged. Otherwise, a new copy of the set is returned containing the value.

let mergeMany: array('value) => t('value'id) => t('value'id);

Immutably merge an array of values into a set.

Note: unlike add if the set already contains all the values in the array, the return value may or may not be a new reference. Otherwise, a new set reference is returned.

let remove: 'value => t('value'id) => t('value'id);

Immutably remove a value from a set. If the value is not found in the set, the original set (physical reference) is returned unchanged. Otherwise, a new set is returned containing the value.

let removeMany: array('value) => t('value'id) => t('value'id);

Immutably remove multiple values from a set. Note: unlike remove, if none of the values in the array are found in the set, the return value may or may not be a new reference. Otherwise, a new set reference is returned.

let update: 'value => t('value'id) => t('value'id);

Immutably update a set with a new value. If an equivalent value already exists in the set, it will be immutably removed before adding the new value. In ether case, a new physical reference to the set will be returned.

Note: unlike add, update guarantees that the value's physical reference will be added to the set.

let toggle: 'value => t('value'id) => t('value'id);

Immutably add a value to a set if it does not already exist. If an equivalent value already exists in the set, it will be removed. In either case, a new physical reference to the set will be returned.

let union: t('value'id) => t('value'id) => t('value'id);

Returns a new set representing the union of two sets.

let s1 = fromList([1, 3, 4, 5, 2, 1]);
let s2 = fromList([1, 0, 3, 2, 9]);
Set.union(s1, s2) |> toList == [0, 1, 2, 3, 4, 5, 9];
let intersect: t('value'id) => t('value'id) => t('value'id);

Returns a new set representing the intersection of two sets.

let s1 = fromList([0, 1, 2, 3, 4, 1]);
let s2 = fromList([0, 3, 9, 8, 10]);
Set.intersect(s1, s2) |> toList == [0, 3];
let diff: t('value'id) => t('value'id) => t('value'id);

Returns a new set which contains all the elements of the first set that are not present in the second set.

Note: The argument order is significant for this function.

let s1 = fromList([0, 1, 2, 3, 4, 1]);
let s2 = fromList([0, 3, 9, 8, 10]);

diff(s1, s2) |> toList == [1, 2, 4];
diff(s2, s1) |> toList == [8, 9, 10];
let subset: t('value'id) => t('value'id) => bool;

subset(s1, s2) will return true if s2 is a subset of s1.

Note: The argument order is significant for this function.

let compare: t('value'id) => t('value'id) => int;

Returns an integer value of -1 | 0 | 1, representing the total ordering between two sets. This can be used as a comparator function to determine the ordering of nested sets (e.g. Set.t(Set.t('a)));

Note: The argument order is significant for this function.

let s0 = Test1.fromList([1, 2, 3, 4]);
let s1 = Test1.fromList([1, 2, 3, 4]);
let s2 = Test1.fromList([2, 3, 4, 5, 6]);
let s3 = Test1.fromList([100, 0]);

Set.compare(s0, s1) == 0;
Set.compare(s0, s2) == -1;
Set.compare(s0, s3) == 1;

Set.compare(s1, s2) == -1;
Set.compare(s1, s3) == 1;
Set.compare(s2, s3) == 1;
let eq: t('value'id) => t('value'id) => bool;

Determine whether two sets are equivalent.

let forEach: ('value => unit) => t('value'id) => unit;

Apply a function to each element of a set, in increasing order.

let foldLeft: ('acc => 'value => 'acc) => 'acc => t('value'id) => 'acc;

Iterate over the values of a set in increasing order, accumulating a final value of an arbitraty type.

let foldRight: ('b => 'a => 'a) => 'a => t('b'id) => 'a;

TODO: optimize foldRight for sets. This remains unimplemented in Belt's API, but it exists in PureScript/Haskell, since Set implements Foldable.

let all: ('value => bool) => t('value'id) => bool;

Determine whether a given predicate holds true for all values in a given set.

let any: ('value => bool) => t('value'id) => bool;

Determine whether a given predicate holds true for at least one value in a given set.

let filter: ('value => bool) => t('value'id) => t('value'id);

Create a new set from another set containing only the values which pass a given test (the predicate function).

let keep: ('value => bool) => t('value'id) => t('value'id);

Set.keep is an alias for filter.

let filterNot: ('value => bool) => t('value'id) => t('value'id);

Creates a new set from another set containing only the values which do not pass a given test (the predicate function)

let reject: ('value => bool) => t('value'id) => t('value'id);

Set.reject is an alias for val.filterNot.

let partition: ('value => bool) => t('value'id) => (t('value'id), t('value'id));

Immutably divide a set into a tuple of two sets, where the first set contains all the values which pass the predicate function test, and the second one contains all the values which fail.

let length: t('value'id) => int;

Returns the total number of elements in a set.

let toArray: t('value'id) => array('value);

Creates a new array containing all elements of the set in ascending order based on the associated comparator function.

let toList: t('value'id) => list('value);

Creates a new list containing all elements of the set in ascending order based on the associated comparator function.

let minimum: t('value'id) => option('value);

Optionally returns the lowest ordered element in a given set or None if the set is empty.

let maximum: t('value'id) => option('value);

Optionally returns the highest ordered element in a given set or None if the set is empty.

let get: 'value => t('value'id) => option('value);

Optionally returns an equivalent element from a set or None if no equivalent element is found, or the set is empty.

let getOrElse: 'value => 'value => t('value'id) => 'value;

Returns an equivalent element from a set if one exists, or else returns a specified default value.

let split: 'value => t('value'id) => ((t('value'id), t('value'id)), bool);

TODO: Needs documentation. Belt doesn't provide much description.

module type SET = { ... };
module WithOrd: (M: BsBastet.Interface.ORD) => SET with type value = M.t;