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

    Function distinct

    • Creates a task discarding repeated items.

      Items are emitted lazily, 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

      Retains every key seen so far in memory. For large or infinite feeds carrying many distinct keys, this may exhaust memory.

      Type Parameters

      • V

        The type of items in the feed

      • K

        The type of the comparison key

      Parameters

      • Optionalselector: (item: 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 }]