yta
    Preparing search index...

    Function uniqueOn

    • Filter items in the iterator such that no two items fulfill the same predicate.

      import { pipe } from "yta";
      import { of, toArray, uniqueOn } from "yta/async";

      await pipe(
      of(
      { id: 1, type: "a" },
      { id: 2, type: "b" },
      { id: 3, type: "a" },
      { id: 4, type: "c" },
      ),
      uniqueOn(({ type }) => type),
      toArray(),
      );
      // => [
      // { id: 1, type: "a" },
      // { id: 2, type: "b" },
      // { id: 4, type: "c" },
      // ]

      Type Parameters

      • A

        The item type

      • P

        The predicate type

      Parameters

      • p: (item: A) => P

        The predicated function

      Returns (items: AsyncIterable<A>) => AsyncGenerator<A, void>