reject
reject() function
The opposite of filter Iterable/AsyncIterable of all elements f
returns falsy for
Signature:
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>>;
Returns:
IterableIterator<A extends object ? ExcludeObject<A, B> : Exclude<A, B>>
Example
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]