Function first

  • Yields the first element in an input iterable that satisfies an optional async predicate function. If no predicate is provided, the first element in the iterable is yielded.

    Returns

    A function that accepts an input iterable and returns a new asynchronous iterable.

    Example

    const input = [1, 2, 3, 4];
    const isEven = async (x: number) => x % 2 === 0;
    const firstIterable = first<number>(isEven)(input);

    (async () => {
    for await (const x of firstIterable) {
    console.log(x); // Logs 2
    }
    })();

    Type Parameters

    • T

      The type of elements in the input iterable.

    Parameters

    • Optional predicate: AsyncArrayLikePredicate<T>

      An optional async predicate function to test each element of the input iterable.

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

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

        Returns AsyncIterable<Awaited<T>>

Generated using TypeDoc