dataprep/non_empty_list
Types
NonEmptyList guarantees at least one element. Used by Invalid to ensure every failure carries at least one error.
pub type NonEmptyList(a) {
NonEmptyList(first: a, rest: List(a))
}
Constructors
-
NonEmptyList(first: a, rest: List(a))
Values
pub fn append(
left left: NonEmptyList(a),
right right: NonEmptyList(a),
) -> NonEmptyList(a)
Concatenate two NonEmptyLists.
pub fn concat(
lists: NonEmptyList(NonEmptyList(a)),
) -> NonEmptyList(a)
Flatten a NonEmptyList of NonEmptyLists into a single NonEmptyList.
pub fn cons(
head head: a,
tail tail: NonEmptyList(a),
) -> NonEmptyList(a)
Prepend an element to a NonEmptyList.
pub fn flat_map(
nel: NonEmptyList(a),
f: fn(a) -> NonEmptyList(b),
) -> NonEmptyList(b)
Map then flatten.
pub fn from_list(l: List(a)) -> Result(NonEmptyList(a), Nil)
Try to create a NonEmptyList from a List. Returns Error(Nil) if the list is empty.
pub fn map(
nel: NonEmptyList(a),
f: fn(a) -> b,
) -> NonEmptyList(b)
Transform every element.