Module Js.SetSource

Provides bindings for ES6 Set

Mutable, insertion-ordered set matching JS Set semantics: iteration order is insertion order, re-adding an existing value keeps its position, and deleting then re-adding a value moves it to the end.

Divergences from JavaScript:

Sourcetype 'a t

The Set type

Sourceval make : unit -> 'a t

make () creates a new empty set.

Sourceval fromArray : 'a array -> 'a t

fromArray values creates a set from an array, deduplicating values. A duplicated value keeps the position of its first occurrence, like JS new Set(values).

Sourceval toArray : 'a t -> 'a array

toArray set returns the values in insertion order, like JS Array.from(set).

Sourceval size : 'a t -> int

size set returns the number of values in set.

Sourceval add : value:'a -> 'a t -> 'a t

add ~value set adds value to set (mutating it) and returns set for chaining. Adding an existing value is a no-op that keeps its original position.

Sourceval clear : 'a t -> unit

clear set removes all values from set.

Sourceval delete : value:'a -> 'a t -> bool

delete ~value set removes value from set; returns whether the value was present.

Sourceval forEach : f:('a -> unit) -> 'a t -> unit

forEach ~f set calls f value for each value in insertion order.

Sourceval has : value:'a -> 'a t -> bool

has ~value set returns whether value is present in set.

Sourceval values : 'a t -> 'a Js__.Js_iterator.t

values set returns an iterator over the values in insertion order.

Sourceval entries : 'a t -> ('a * 'a) Js__.Js_iterator.t

entries set returns an iterator over (value, value) pairs in insertion order, like JS Set.prototype.entries.