dropWhile() function
返回排除从开头删除的元素的 Iterable/AsyncIterable。删除元素直到应用于 f 的值返回假值。
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]