NonEmptyList
is a non-empty list, useful for modeling data with one or more occurence.
Example:
Order : { items : NonEmptyList Item ,
customer : CustomerInfo
}
There are two ways to construct a NonEmptyList
. It can either be constructed using fromList
, or single
.
This API implements many of the functions in the built-in List
. For the functions that are missing, you can drop down to a regular List
using toList
.
fromList : List a -> Result (NonEmptyList a) [ListWasEmpty]Construct a non-empty list from a List
. Returns ListWasEmpty
if the original list was empty.
single : a -> NonEmptyList aConstructs a "singleton" NonEmptyList
from a single element.
toList : NonEmptyList a -> List aTransform the non-empty list to a list.
expect NonEmptyList . single "a" |> NonEmptyList . append "b" |> NonEmptyList . toList == [ "a" , "b" ]
last : NonEmptyList a -> a
first : NonEmptyList a -> a
min : NonEmptyList (Num a) -> Num a
max : NonEmptyList (Num a) -> Num a
singleThenRepeat : a, Nat -> NonEmptyList aAdd one occurence of an element and then repeat it the specified number of times.
expect "a" |> NonEmptyList . singleThenRepeat 5 |> NonEmptyList . len == 6
takeFirstAnd : NonEmptyList elem, Nat -> NonEmptyList elemTake the first element and then the following specified number of elements.
takeLastAnd : NonEmptyList elem, Nat -> NonEmptyList elemTake the last element and then the preceeding specified number of elements
get : NonEmptyList a, Nat -> Result a [OutOfBounds]
replace :
NonEmptyList a,
Nat,
a
->
{
nonemptylist : NonEmptyList a,
value : a
}
set :
NonEmptyList a,
Nat,
a
-> NonEmptyList a
update :
NonEmptyList a,
Nat,
(a -> a)
-> NonEmptyList a
append : NonEmptyList a, a -> NonEmptyList a
appendIfOk : NonEmptyList a, Result a * -> NonEmptyList a
prepend : NonEmptyList a, a -> NonEmptyList a
prependIfOk : NonEmptyList a, Result a * -> NonEmptyList a
len : NonEmptyList * -> Nat
concat : NonEmptyList a, NonEmptyList a -> NonEmptyList a
reverse : NonEmptyList a -> NonEmptyList a
join : NonEmptyList (NonEmptyList a) -> NonEmptyList a
contains : NonEmptyList a, a -> Bool
where a implements Eq
walk :
NonEmptyList elem,
state,
(state, elem -> state)
-> state
walkWithIndex :
NonEmptyList elem,
state,
(state,
elem,
Nat
-> state)
-> state
walkBackwards :
NonEmptyList elem,
state,
(state, elem -> state)
-> state
walkUntil :
NonEmptyList elem,
state,
(state,
elem
->
[
Continue state,
Break state
])
-> state
walkBackwardsUntil :
NonEmptyList elem,
state,
(state,
elem
->
[
Continue state,
Break state
])
-> state
walkFrom :
NonEmptyList elem,
Nat,
state,
(state, elem -> state)
-> state
walkFromUntil :
NonEmptyList elem,
Nat,
state,
(state,
elem
->
[
Continue state,
Break state
])
-> state
sum : NonEmptyList (Num a) -> Num a
product : NonEmptyList (Num a) -> Num a
any : NonEmptyList a, (a -> Bool) -> Bool
all : NonEmptyList a, (a -> Bool) -> Bool
countIf : NonEmptyList a, (a -> Bool) -> Nat
map : NonEmptyList a, (a -> b) -> NonEmptyList b
map2 :
NonEmptyList a,
NonEmptyList b,
(a, b -> c)
-> NonEmptyList c
map3 :
NonEmptyList a,
NonEmptyList b,
NonEmptyList c,
(a,
b,
c
-> d)
-> NonEmptyList d
map4 :
NonEmptyList a,
NonEmptyList b,
NonEmptyList c,
NonEmptyList d,
(a,
b,
c,
d
-> e)
-> NonEmptyList e
mapWithIndex : NonEmptyList a, (a, Nat -> b) -> NonEmptyList b
sortWith :
NonEmptyList a,
(a,
a
->
[
LT,
EQ,
GT
])
-> NonEmptyList a
sortAsc : NonEmptyList (Num a) -> NonEmptyList (Num a)
sortDesc : NonEmptyList (Num a) -> NonEmptyList (Num a)
swap :
NonEmptyList a,
Nat,
Nat
-> NonEmptyList a
joinMap : NonEmptyList a, (a -> NonEmptyList b) -> NonEmptyList b
findFirst : NonEmptyList elem, (elem -> Bool) -> Result elem [NotFound]
findLast : NonEmptyList elem, (elem -> Bool) -> Result elem [NotFound]
findFirstIndex : NonEmptyList elem, (elem -> Bool) -> Result Nat [NotFound]
findLastIndex : NonEmptyList elem, (elem -> Bool) -> Result Nat [NotFound]
intersperse : NonEmptyList elem, elem -> NonEmptyList elem
startsWith : NonEmptyList elem, NonEmptyList elem -> Bool
where elem implements Eq
endsWith : NonEmptyList elem, NonEmptyList elem -> Bool
where elem implements Eq
chunksOf : NonEmptyList a, Nat -> List (NonEmptyList a)
mapTry : NonEmptyList elem, (elem -> Result ok err) -> Result (NonEmptyList ok) err
walkTry :
NonEmptyList elem,
state,
(state, elem -> Result state err)
-> Result state err