Function firstSync

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

    Returns

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

    Example

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

    for (const x of firstSyncIterable) {
    console.log(x); // Logs 2
    }

    Remarks

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

    Type Parameters

    • T

      The type of elements in the input sync iterable.

    Parameters

    • Optional predicate: ArrayLikePredicate<T>

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

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

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

        • input: Iterable<T>

        Returns Iterable<T>

Generated using TypeDoc