Skip to content

dropWhile() function

Returns Iterable/AsyncIterable excluding elements dropped from the beginning. Elements are dropped until the value applied to f returns falsey.

Signature:

typescript
declare function dropWhile<A, B = unknown>(f: (a: A) => B, iterable: Iterable<A>): IterableIterator<A>;

Example

ts
const iter = dropWhile((a) => a < 3, [1, 2, 3, 4, 5]);
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],
 dropWhile((a) => a < 3),
 toArray,
); // [3, 4, 5]

await pipe(
 Promise.resolve([1, 2, 3, 4, 5]),
 dropWhile((a) => a < 3),
 toArray,
); // [3, 4, 5]

// if you want to use asynchronous callback
await pipe(
 Promise.resolve([1, 2, 3, 4, 5]),
 toAsync,
 dropWhile(async (a) => a < 3),
 toArray,
); // [3, 4, 5]

// with toAsync
await pipe(
 [Promise.resolve(1), Promise.resolve(2), Promise.resolve(3), Promise.resolve(4), Promise.resolve(5)],
 toAsync,
 dropWhile((a) => a < 3),
 toArray,
); // [3, 4, 5]

see pipe, toAsync, toArray

Open Source Code

Released under the Apache-2.0 License.