interface NonEmptyListTypeRef {
    fromArray<T>(
        source: readonly T[],
    ): functional.Maybe<functional.NonEmptyList<T>>;
    fromTuple<T, U>(
        source: functional.Tuple<T, U>,
    ): functional.NonEmptyList<T | U>;
    head<T>(list: functional.NonEmptyList<T>): T;
    isNonEmpty<T>(list: readonly T[]): list is functional.NonEmptyList<T>;
    last<T>(list: functional.NonEmptyList<T>): T;
    tail<T>(list: functional.NonEmptyList<T>): T[];
    unsafeCoerce<T>(source: readonly T[]): functional.NonEmptyList<T>;
    <T extends functional.NonEmptyListCompliant<T[number]>>(
        list: T,
    ): functional.NonEmptyList<T[number]>;
}

Methods

  • The same function as List#head, but it doesn't return a Maybe as a NonEmptyList will always have a head

    Type Parameters

    • T

    Parameters

    Returns T

  • Returns true and narrows the type if the passed array has one or more elements

    Type Parameters

    • T

    Parameters

    • list: readonly T[]

    Returns list is functional.NonEmptyList<T>

  • The same function as List#last, but it doesn't return a Maybe as a NonEmptyList will always have a last element

    Type Parameters

    • T

    Parameters

    Returns T

  • The same function as List#tail, but it doesn't return a Maybe as a NonEmptyList will always have a tail (although it may be of length 0)

    Type Parameters

    • T

    Parameters

    Returns T[]

  • Typecasts any array into a NonEmptyList, but throws an exception if the array is empty. Use fromArray as a safe alternative

    Type Parameters

    • T

    Parameters

    • source: readonly T[]

    Returns functional.NonEmptyList<T>