Js.SetSourceProvides 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:
=) instead of SameValueZero. Consequently nan compares unequal to itself (has ~value:nan is false after add ~value:nan, whereas JS Sets treat NaN as a single value), and two structurally equal but physically distinct mutable values (e.g. two arrays [|1|]) are the same element here while JS would keep them separate.values/entries return a snapshot iterator: mutations made after the iterator is created are not observed, whereas JS Set iterators are live.The Set type
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).
toArray set returns the values in insertion order, like JS Array.from(set).
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.
delete ~value set removes value from set; returns whether the value was present.
forEach ~f set calls f value for each value in insertion order.
values set returns an iterator over the values in insertion order.