Function findSync

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

    Returns

    A function that accepts an input sync iterable and returns the found element or undefined.

    Example

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

    Remarks

    Available as find when imported from peter-piper/sync.

    Type Parameters

    • T

      The type of elements in the input sync iterable.

    Parameters

    • predicate: ArrayLikePredicate<T>

      A predicate function to test each element of the input sync iterable.

    Returns ((input: Iterable<T>) => undefined | T)

      • (input: Iterable<T>): undefined | T
      • Parameters

        • input: Iterable<T>

        Returns undefined | T

Generated using TypeDoc