Skip to content

dropWhile() function

처음부터 삭제된 요소를 제외한 Iterable/AsyncIterable을 반환합니다. f에 적용된 값이 거짓(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.