dataprep/non_empty_list
Types
NonEmptyList guarantees at least one element. Used by Invalid to ensure every failure carries at least one error.
The type is opaque: callers construct values via single / cons /
from_list and observe values via head / tail / to_list /
fold / length / reverse. Hiding the constructor lets the
internal representation evolve without a breaking release.
pub opaque type NonEmptyList(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 fold(
nel: NonEmptyList(a),
from initial: b,
with f: fn(b, a) -> b,
) -> b
Fold over every item from an initial accumulator.
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 head(nel: NonEmptyList(a)) -> a
Return the first element. Total: a NonEmptyList always has one.
pub fn map(
nel: NonEmptyList(a),
f: fn(a) -> b,
) -> NonEmptyList(b)
Transform every element.
pub fn reverse(nel: NonEmptyList(a)) -> NonEmptyList(a)
Reverse the order of elements. The result is itself a NonEmptyList.
pub fn tail(nel: NonEmptyList(a)) -> List(a)
Return everything after the first element as a plain List. May be empty when the NonEmptyList holds a single element.