Skip to content

uniq() function

指定された Iterable/AsyncIterable 内の重複値を削除した Iterable/AsyncIterable を返します。プリミティブ値のみが比較可能です。結果の値の順序は、配列内で出現する順序によって決定されます。

Signature:

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

Example

ts
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

Released under the Apache-2.0 License.