Function take

  • Lazily takes the first n elements from the input iterable. Returns an async iterable with the first n elements of the input iterable.

    Returns

    A function that accepts an input iterable and returns an async iterable with the first n elements of the input iterable.

    Example

    const input = asyncIterable([1, 2, 3, 4, 5]);
    const takeThree = take(3)(input);

    (async () => {
    for await (const value of takeThree) {
    console.log(value); // Logs 1, 2, 3
    }
    })();

    Type Parameters

    • T

      The type of elements in the input iterable.

    Parameters

    • n: number

      The number of elements to take from the input iterable.

    Returns ((input: AnyIterable<T>) => AsyncIterable<Awaited<T>>)

      • (input: AnyIterable<T>): AsyncIterable<Awaited<T>>
      • Parameters

        Returns AsyncIterable<Awaited<T>>

Generated using TypeDoc