@telostat/prelude - v0.7.0
    Preparing search index...

    Interface NonEmptyListTypeRef

    interface NonEmptyListTypeRef {
        fromArray<T>(source: readonly T[]): Maybe<NonEmptyList<T>>;
        fromTuple<T, U>(source: Tuple<T, U>): NonEmptyList<T | U>;
        head<T>(list: NonEmptyList<T>): T;
        isNonEmpty<T>(list: readonly T[]): list is NonEmptyList<T>;
        last<T>(list: NonEmptyList<T>): T;
        tail<T>(list: NonEmptyList<T>): T[];
        unsafeCoerce<T>(source: readonly T[]): NonEmptyList<T>;
        <T extends NonEmptyListCompliant<T[number]>>(
            list: T,
        ): NonEmptyList<T[number]>;
    }
    • Typecasts an array with at least one element into a NonEmptyList. Works only if the compiler can confirm that the array has one or more elements

      Type Parameters

      Parameters

      • list: T

      Returns NonEmptyList<T[number]>

    Index

    Methods

    • Returns a Just NonEmptyList if the parameter has one or more elements, otherwise it returns Nothing

      Type Parameters

      • T

      Parameters

      • source: readonly T[]

      Returns Maybe<NonEmptyList<T>>

    • 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 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 NonEmptyList<T>