Module Alg_structs.NonEmptyList
Non-empty lists
include Functor.S with type 'a t := 'a t
include Functor.Seed
type 'a t
The principle type.
The type constructor
t
is the mapping of objects taking every type'a
to a type'a t
.
val map : f:('a -> 'b) -> 'a t -> 'b t
map ~f
maps the functionf : 'a -> 'b
to a function'f T : 'a T -> 'b T
.As an example, if
T (x : u) : u t
thenmap ~(f:u -> v) (T x)
isT (f x) : v t
. As a result,map
is often thought of as applyingf
"in"T
.The function
map
is the mapping of arrows, taking every arrow'a -> 'b
to an arrow'a t -> 'b t
.
val uncons : 'a t -> 'a * 'a list
uncons t
is(List.hd t, List.tl t)
.
val hd : 'a t -> 'a
hd t
is the first element oft
.Since
t
is non-empty, it is guaranteed that there will always be a head.
val tl : 'a t -> 'a list
tl t
are the elements oft
after, but not including the head.Since
t
is non-empty, it is guaranteed that there will always be a tail.
val fold : ('a -> 'a -> 'a) -> 'a t -> 'a
See
List.concat
.
val of_list : 'a list -> 'a t option
of_list xs
is aSome
non-empty list ofxs
ifxs
isn't empty. Otherwise it isNone
.
val to_list : 'a t -> 'a list
to_list t
is the list of the elements int
.