Function distinct

  • Emits unique values, with optional key selector.

    import {pipe, distinct} from 'iter-ops';

    const i = pipe(
    [1, 1, 1, 2, 2, 2, 3, 3],
    distinct() // selector not needed for simple types
    );

    console.log(...i); //=> 1, 2, 3

    With optional selector function:

    import {pipe, distinct} from 'iter-ops';

    const i = pipe(
    [{a: 1}, {a: 1}, {a: 2}, {a: 2}],
    distinct(v => v.a)
    );

    console.log(...i); //=> {a: 1}, {a: 2}

    Type Parameters

    • T
    • K

    Parameters

    • OptionalkeySelector: ((value: T, index: number) => K)
        • (value, index): K
        • Parameters

          • value: T
          • index: number

          Returns K

    Returns Operation<T, T>