• Find the first matching element of an Iterable, or a default value if the Iterable is empty.

    Returns undefined if the Iterable is empty and no defaultValue was provided.

    Example

    Get the first matching element

    const findFirstEven = findFirst(isEven);
    const result = findFirstEven([1,2,3]);
    console.log(result); // 2

    Example

    Get the first matching element or the defaultValue

    const findFirstEven = findFirst(isEven, 2);
    const result = findFirstEven([1]);
    console.log(result); // 2

    See

    filter and first for similar operations.

    Returns

    the first matching element of the Iterable, or the given defaultValue

    Type Parameters

    • T

      the Iterable value type

    Parameters

    • predicate: Predicate<[T]>

      the Predicate to match

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

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

        Returns undefined | T

  • Find the first matching element of an Iterable, or a default value if the Iterable is empty.

    Returns undefined if the Iterable is empty and no defaultValue was provided.

    Example

    Get the first matching element

    const findFirstEven = findFirst(isEven);
    const result = findFirstEven([1,2,3]);
    console.log(result); // 2

    Example

    Get the first matching element or the defaultValue

    const findFirstEven = findFirst(isEven, 2);
    const result = findFirstEven([1]);
    console.log(result); // 2

    See

    filter and first for similar operations.

    Returns

    the first matching element of the Iterable, or the given defaultValue

    Type Parameters

    • T

      the Iterable value type

    Parameters

    • predicate: Predicate<[T]>

      the Predicate to match

    • defaultValue: T

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

Generated using TypeDoc