• Get the first element of an Iterable, or an optional default value if the Iterable is empty.

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

    Example

    Get the first element

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

    Example

    Get the first element or the defaultValue

    const result = first(1)([]);
    console.log(result); // 1

    See

    filter and find for similar operations.

    Returns

    the first element of the Iterable, or the defaultValue

    Type Parameters

    • T

      the Iterable value type

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

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

        Returns undefined | T

  • Get the first element of an Iterable, or an optional default value if the Iterable is empty.

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

    Example

    Get the first element

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

    Example

    Get the first element or the defaultValue

    const result = first(1)([]);
    console.log(result); // 1

    See

    filter and find for similar operations.

    Returns

    the first element of the Iterable, or the defaultValue

    Type Parameters

    • T

      the Iterable value type

    Parameters

    • defaultValue: T

      the default value

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

Generated using TypeDoc