Yocaml.NelSourceA Nel, for Non Empty List, is a list that ensures it has at least one element, which is very useful for describing, for example, error lists, where if there is an error, we ensure that there is at least one error.
A non-empty list is nothing more than a pair of a value and a list.
cons x xs constructs a non-empty list whose head is x and whose tail is xs.
init len f is f 0; f 1; ...; f (len-1), evaluated left to right.
from_list l convert a regular list to a non-empty one, if the given list is empty the function returns None.
from_seq l convert a regular seq to a non-empty one, if the given seq is empty the function returns None.
is_singleton x returns true if the non-empty list has just one element, false otherwise.
hd nel returns the head of the non-empty list. Since the list can't be empty, the function never fail.
tl nel returns the tail of the non-empty list. Since the list can't be empty, the function never fail.
rev_append nel1 nelt2 reverses nel1 and concatenates it with nel2. This is equivalent to (Nel.rev nel1) @ nel2.
concat nel Concatenate a non-empty list of non-empty lists. The elements of the argument are all concatenated together (in the same order) to give the result.
iteri f nel same as iter but the function is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.
map f nel build a new non-empty list applying f on each element of the non-empty list.
mapi f nel same as map but the function is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.
rev_map f nel is a more efficient way of making Nel.(rev (map f nel)).
rev_mapi f nel same as rev_map but the function is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.
flat_map f nel same as concat_map (present for convention reason).
concat_mapi f nel same as concat_map but the function is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.
fold_left reducer default nel is fold_left f init [b1; ...; bn] is f (... (f (f init b1) b2) ...) bn.
fold_lefti f default nel same as fold_left but the function is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.
fold_right f nel default is fold_right f [a1; ...; an] init is f a1 (f a2 (... (f an init) ...)).
fold_righti f nel default same as fold_right but the function is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.
val pp :
?pp_sep:(Format.formatter -> unit -> unit) ->
(Format.formatter -> 'a -> unit) ->
Format.formatter ->
'a t ->
unitPretty-printer based on Format.pp_print_list.