Abstract around NonEmptyList<A>, which is similar to a Cons-style list, but must contain at least one element (cannot be empty).

Static methods

@:op(N + N0)staticappend(this:NonEmptyList<A>, nel:Nel<A>):Nel<A>

Appends another non-empty list to this Nel<A>.

Warning: this operation is O(n)

staticconcat(this:NonEmptyList<A>, xs:Array<A>):Nel<A>

staticcons<A>(a:A, nl:Nel<A>):Nel<A>

Constructs a Nel<A> from a head element and tail Nel<A>

staticflatMap<B>(this:NonEmptyList<A>, f:A ‑> Nel<B>):Nel<B>

Applies an A -> Nel<B> function to each element in this Nel<A> and flattens the result to create a new Nel<B>

staticfold(this:NonEmptyList<A>, f:(A, A) ‑> A):A

Applies a reducing function to this Nel<A>

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.

statichead(this:NonEmptyList<A>):A

Gets the head item of this Nel<A>, which is guaranteed to exist

staticinit(this:NonEmptyList<A>):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)

staticintersperse(this:NonEmptyList<A>, a:A):Nel<A>

staticlast(this:NonEmptyList<A>):A

Gets the last item of the Nel<A>, which is guaranteed to exist.

Warning: this operation is O(n)

staticmap<B>(this:NonEmptyList<A>, f:A ‑> B):Nel<B>

Applies an A -> B function to each element in this Nel<A> to create a new Nel<B>

staticnel<A>(hd:A, tl:Array<A>):Nel<A>

Constructs a Nel<A> from a head element and tail Array<A>

staticpop(this:NonEmptyList<A>):Tuple<A, ReadonlyArray<A>>

Returns the last item of the Nel<A> and a new Nel<A> with the last item removed.

Does not modify this Nel<A>.

Warning: this operation is O(n)

staticpure<A>(a:A):Nel<A>

Constructs a Nel<A> from a head element

staticpush(this:NonEmptyList<A>, a:A):Nel<A>

Returns a new Nel<A> with the given item added at the end.

Does not modify this Nel<A>.

Warning: this operation is O(n)

staticsemigroup<A>():Semigroup<Nel<A>>

Gets a Semigroup instance for Nel<A>, using the append method of Nel<A>.

staticshift(this:NonEmptyList<A>):Tuple<A, ReadonlyArray<A>>

Returns the first item of the Nel<A> and a new Nel<A> with the first item removed.

Does not modify this Nel<A>.

statictail(this:NonEmptyList<A>):ReadonlyArray<A>

Gets the tail (all but the first element) of the Nel<A> as a possibly-empty ReadonlyArray<A>

statictoArray(this:NonEmptyList<A>):ReadonlyArray<A>

Converts the Nel<A> to a ReadonlyArray<A>

Warning: this operation is O(n)

staticunshift(this:NonEmptyList<A>, a:A):Nel<A>

Returns a new Nel<A> with the given item added at the front.

Does not modify this Nel<A>.