NonEmpty
Import NonEmpty when a sequence must contain at least one value.
Type and constructor
NonEmpty
The public constructor stores the guaranteed head followed by an ordinary list tail. The same name refers to the type and its constructor.
NonEmpty
The constructor is available to patterns.
Construction and conversion
nonEmptySingleton
nonEmptyFromList
Returns Nothing for []; otherwise stores the list head and tail without
traversing them. This is O(1).
nonEmptyToList
nonEmptyPrepend
Adds a new first value in O(1).
nonEmptyAppendList
Appends an ordinary list after the non-empty sequence. This is O(n) in the
original sequence tail.
Access
nonEmptyHead
Total and O(1).
nonEmptyTail
The result may be empty. This is O(1).
nonEmptyLast
Returns the final value. The function is total and O(n).
nonEmptyLength
Returns the number of values, which is always at least one. This is O(n).
Transforming and folding
nonEmptyMap
Transforms every value in order and preserves non-emptiness. This is O(n)
plus callback work.
nonEmptyFoldLeft
Combines values from head to last, beginning with the supplied accumulator.
This is O(n) plus callback work.
nonEmptyFoldRight
Combines values from last to head, beginning with the supplied terminal value.
This is O(n) plus callback work.