yta
    Preparing search index...

    Function takeWhile

    • Take the first items from the iterator while the predicate function holds true, after that the iterator closes.

      import { pipe } from "yta";
      import { takeWhile, toArray } from "yta/async";
      import { asAsync, range } from "yta/async";

      await pipe(
      range(10),
      asAsync(),
      takeWhile((n) => n < 5),
      toArray(),
      );
      // => [0, 1, 2, 3, 4]

      See also:

      Type Parameters

      • A

        The item type

      Parameters

      • p: (item: A) => boolean

        The predicate function

      Returns (items: AsyncIterable<A>) => AsyncGenerator<A, void>