dropUntil() function
先頭から削除された要素を除外した Iterable/AsyncIterable を返します。f に適用された値が truthy を返すまで要素は削除されます(true として適用された最初の値を含めて削除されます)。
Signature:
typescript
declare function dropUntil<A, B = unknown>(
f: (a: A) => B,
iterable: Iterable<A>,
): IterableIterator<A>;Example
ts
const iter = dropUntil((a) => a > 3, [1, 2, 3, 4, 5, 1, 2]);
iter.next(); // {done:false, value: 5}
iter.next(); // {done:false, value: 1}
iter.next(); // {done:false, value: 2}
// 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]