@metreeca/flow - v0.10.0
    Preparing search index...

    Function toSet

    • Creates a sink collecting the distinct items of the feed into a set.

      Items are made immutable as they are collected, in first-appearance order, and compared with SameValueZero semantics, so NaN matches itself and -0 matches 0.

      The returned set is frozen, with add, delete and clear shadowed by own properties that throw: entries cannot be altered through the set, although mutating methods invoked directly on Set.prototype still reach the internal slots backing them.

      Warning

      • Exhaustive: every item is collected before the sink resolves, so an infinite feed never completes.
      • Materialising: the whole feed is held in memory, so a large feed may exhaust it.
      • Stateful: the set covers the items drawn, so a sink closing a nested or truncated feed sees those alone.
      Warning

      Freezing clones structured items, giving them a fresh identity: entries are not reachable through the original item reference, and the same mutable item collected twice yields two distinct entries rather than being deduplicated. Supply structured items as immutable values to keep their identity stable.

      Type Parameters

      • V

        The type of items in the feed

      Returns Sink<V, ReadonlySet<V>>

      A sink resolving to the deeply immutable read-only set of the distinct items of the feed

      await pipe(
      (items([1, 2, 2, 3, 3, 3]))
      (toSet())
      ); // Set(3) { 1, 2, 3 }