Function find

  • Finds the first element in an input iterable that satisfies a given async predicate function. Returns a Promise of the found element or undefined if none is found.

    Returns

    A function that accepts an input iterable and returns a Promise of the found element or undefined.

    Example

    const input = [1, 2, 3, 4];
    const isEven = async (x: number) => x % 2 === 0;
    const foundElement = await find<number>(isEven)(input);
    console.log(foundElement); // Logs 2

    Type Parameters

    • T

      The type of elements in the input iterable.

    Parameters

    Returns ((input: AnyIterable<T>) => Promise<undefined | T>)

      • (input: AnyIterable<T>): Promise<undefined | T>
      • Parameters

        Returns Promise<undefined | T>

Generated using TypeDoc