Skip to content

dropUntil() function

처음부터 삭제된 요소를 제외한 Iterable/AsyncIterable을 반환합니다. f에 적용된 값이 참(truly)을 반환할 때까지 요소가 삭제됩니다. (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]

see pipe, toAsync, toArray

Open Source Code

Released under the Apache-2.0 License.