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

    Function distinct

    • Creates a task discarding repeated items.

      Items are emitted in source order, keeping the first occurrence of each key and discarding the ones following it. Keys are compared with SameValueZero semantics, so NaN matches itself and -0 matches 0, and structured keys are matched by identity rather than by content.

      Warning

      • Incremental: items are emitted as they are drawn, so the reported feed runs dry as the feed drawn from does.
      • Materialising: every key seen so far is held in memory, so a feed carrying many distinct keys may exhaust it.
      • Stateful: the keys already seen decide the items that follow, so a task invoked per nested feed or per run deduplicates within each rather than across the feed as a whole.

      Type Parameters

      • V

        The type of items in the feed

      • K

        The type of the comparison key

      Parameters

      • Optionalselector: (item: NoInfer<V>) => Awaitable<K>

        The function extracting the comparison key from each item; items are compared directly when omitted

      Returns Task<V>

      A task yielding the first item bearing each distinct key

      await pipe(
      (items([1, 2, 2, 3, 1]))
      (distinct())
      (toArray())
      ); // [1, 2, 3]

      await pipe(
      (items([{ id: 1 }, { id: 2 }, { id: 1 }]))
      (distinct(x => x.id))
      (toArray())
      ); // [{ id: 1 }, { id: 2 }]