Abstract around NonEmptyList<A>
, which is similar to a Cons-style list, but must contain
at least one element (cannot be empty).
Methods
Appends another non-empty list to this Nel<A>
.
Warning: this operation is O(n)
init ():ReadonlyArray<A>
Gets the initial elements (all but the last element) of the Nel<A>
as a possibly-empty ReadonlyArray<A>
Warning: this operation is O(n)
last ():A
Gets the last item of the Nel<A>
, which is guaranteed to exist.
Warning: this operation is O(n)
pop ():Tuple<A, ReadonlyArray<A>>
shift ():Tuple<A, ReadonlyArray<A>>
tail ():ReadonlyArray<A>
Gets the tail (all but the first element) of the Nel<A>
as a possibly-empty ReadonlyArray<A>
toArray ():ReadonlyArray<A>
Converts the Nel<A>
to a ReadonlyArray<A>
Warning: this operation is O(n)
Static methods
staticfromArray<A> (arr:ReadonlyArray<A>):Option<Nel<A>>
Attempts to construct a Nel<A>
from a possibly-empty Array<A>
. If the array
is empty, None
is returned.