Implementation for Nonempty_list.t
.
A Nonempty_list.t
is a list that contains at least one element. Therefore, the head and tails functions are total and safe.
Type
Implementation
Functor
Alt
Applicative
Nonempty_list.t
implements Preface_specs.APPLICATIVE
and introduces an interface to define Preface_specs.TRAVERSABLE
using Nonempty_list
as an iterable structure.
Selective
Monad
Nonempty_list.t
implements Preface_specs.MONAD
and introduces an interface to define Preface_specs.TRAVERSABLE
using Nonempty_list
as an iterable structure.
Comonad
Foldable
Delayed implementation
By setting the inner type
type of Nonempty_list.t
it is possible to get implementations for abstractions twithout type parameter.
Semigroup
Addtional functions
Additional functions to facilitate practical work with Nonempty_list.t
.
Create a value from 'a
to 'a t
.
create x
create a new non-empty list with x
.
val from_list : 'a list -> 'a t option
Creates a non-empty list from a regular list.
val to_list : 'a t -> 'a list
Convert non-empty list to a regular list.
Returns the head of a non-empty list.
val tl : 'a t -> 'a t option
Returns the tail of a non-empty list.
Returns the length of a non-empty list.
val cons : 'a -> 'a t -> 'a t
cons x xs
is add x
as head of xs
.
val append : 'a t -> 'a t -> 'a t
append a b
concat a
and b
.
val rev_append : 'a t -> 'a t -> 'a t
rev_append a b
is a tail-recursive version of append (rev a) b
.
val flatten : 'a t t -> 'a t
Concat a non-empty list of non-empty list
val iter : ('a -> unit) -> 'a t -> unit
List.iter
for non-empty list.
val iteri : (int -> 'a -> unit) -> 'a t -> unit
List.iteri
for non-empty list.
val map : ('a -> 'b) -> 'a t -> 'b t
List.map
for non-empty list.
val mapi : (int -> 'a -> 'b) -> 'a t -> 'b t
List.mapi
for non-empty list.
val reduce : ('a -> 'a -> 'a) -> 'a t -> 'a
reduce f xs
reduce all value of xs
into one.
val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a
List.fold_left
for non-empty list.
val fold_right : ('a -> 'b -> 'b) -> 'a t -> 'b -> 'b
List.fold_right
for non-empty list.
val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool
Equality between Nonempty_list.t
.
Formatter for pretty-printing for Nonempty_list.t
.