Skip to main content

first

Callable

  • first<T>(xs: T): T extends readonly [infer N0, ...unknown[]] ? N0 : Maybe<IterableElement<T>>

  • Return the first element of a traversable, or Nothing if the traversable is empty.

    The first function is a good example of how to use the at function. It's also a good example of how to use the Maybe type.

    Example

    first([1, 2, 3])
    // => 1

    first([])
    // => Nothing
    @see

    Type parameters

    • T: Traversable<unknown, unknown> | readonly unknown[]

      The element type.

    Parameters

    • xs: T

      The traversable to find the element in.

    Returns T extends readonly [infer N0, ...unknown[]] ? N0 : Maybe<IterableElement<T>>

    The first element of the traversable, otherwise Nothing.