dropUntil
dropUntil() function
Returns Iterable/AsyncIterable excluding elements dropped from the beginning. Elements are deleted until the value applied to f returns truly. (It is deleted including the first value applied as true)
Signature:
declare function dropUntil<A, B = unknown>(f: (a: A) => B, iterable: Iterable<A>): IterableIterator<A>;
Returns:
IterableIterator<A>
Example
const iter = dropUntil((a) => a < 3, [1, 2, 3, 4, 5, 1, 2]);
iter.next(); // {done:false, value: 3}
iter.next(); // {done:false, value: 4}
iter.next(); // {done:false, value: 5}
// with pipe
pipe(
[1, 2, 3, 4, 5, 1, 2],
dropUntil((a) => a > 3),
toArray,
); // [5, 1, 2]
await pipe(
Promise.resolve([1, 2, 3, 4, 5, 1, 2]),
dropUntil((a) => a > 3),
toArray,
); // [5, 1, 2]
// if you want to use asynchronous callback
await pipe(
Promise.resolve([1, 2, 3, 4, 5, 1, 2]),
toAsync,
dropUntil(async (a) => a > 3),
toArray,
); // [5, 1, 2]
// with toAsync
await pipe(
[Promise.resolve(1), Promise.resolve(2), Promise.resolve(3), Promise.resolve(4),
Promise.resolve(5), Promise.resolve(1), Promise.resolve(2)],
toAsync,
dropUntil((a) => a > 3),
toArray,
); // [5, 1, 2]