reject() function
filter의 반대입니다. f가 falsy를 반환하는 모든 요소의 Iterable/AsyncIterable입니다.
Signature:
typescript
declare function reject<A, B extends A>(
f: (a: A) => a is B,
iterable: Iterable<A>,
): IterableIterator<A extends object ? ExcludeObject<A, B> : Exclude<A, B>>;Example
ts
const iter = reject((a) => a % 2 === 0, [0, 1, 2, 3, 4, 5, 6]);
iter.next(); // {done:false, value: 1}
iter.next(); // {done:false, value: 3}
iter.next(); // {done:false, value: 5}
iter.next(); // {done:true, value: undefined}
// with pipe
pipe(
[0, 1, 2, 3, 4, 5, 6],
reject((a) => a % 2 === 0),
toArray,
); // [1, 3, 5]
await pipe(
Promise.resolve([0, 1, 2, 3, 4, 5, 6]),
reject((a) => a % 2 === 0),
toArray,
); // [1, 3, 5]
// if you want to use asynchronous callback
await pipe(
Promise.resolve([0, 1, 2, 3, 4, 5, 6]),
toAsync,
reject(async (a) => a % 2 === 0),
toArray,
); // [1, 3, 5]
// with toAsync
await pipe(
[
Promise.resolve(0),
Promise.resolve(1),
Promise.resolve(2),
Promise.resolve(3),
Promise.resolve(4),
Promise.resolve(5),
Promise.resolve(6),
],
toAsync,
reject((a) => a % 2 === 0),
toArray,
); // [1, 3, 5]