Skip to main content

uniq

uniq() function

Returns Iterable/AsyncIterable with duplicate values removed inside the given Iterable/AsyncIterable. Only primitive values can be compared. The order of result values is determined by the order they occur in the array.

Signature:
declare function uniq<A extends Iterable<unknown> | AsyncIterable<unknown>>(iterable: A): ReturnIterableIteratorType<A>;

Example

const iter = uniq([1, 2, 1, 3, 2]);
iter.next() // {done:false, value: 1}
iter.next() // {done:false, value: 2}
iter.next() // {done:false, value: 3}
iter.next() // {done:true, value: undefined}

// with pipe
pipe(
[1, 2, 1, 3],
uniq,
toArray,
); // [1, 2, 3]

await pipe(
Promise.resolve([1, 2, 1, 3]),
uniq,
toArray,
); // [1, 2, 3]

// with toAsync
await pipe(
[Promise.resolve(1), Promise.resolve(2), Promise.resolve(1), Promise.resolve(3)],
toAsync,
uniq,
toArray,
); // [1, 2, 3]

Try It

see pipe, toAsync, toArray

Open Source Code