Function first

  • Safely get the first item from a list, returning Just the first item if the array has at least one item in it, or Nothing if it is empty.

    let empty = [];
    Maybe.head(empty); // => Nothing

    let full = [1, 2, 3];
    Maybe.head(full); // => Just(1)

    Type Parameters

    • T

    Parameters

    • array: AnyArray<undefined | null | T>

      The array to get the first item from.

    Returns Maybe<T>