Preface_stdlib.Nonempty_list
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.
module Functor : Preface_specs.FUNCTOR with type 'a t = 'a t
module Alt : Preface_specs.ALT with type 'a t = 'a t
Nonempty_list.t
implements Preface_specs.APPLICATIVE
and introduces an interface to define Preface_specs.TRAVERSABLE
using Nonempty_list
as an iterable structure.
module Applicative :
Preface_specs.Traversable.API_OVER_APPLICATIVE with type 'a t = 'a t
module Selective : Preface_specs.SELECTIVE with type 'a t = 'a t
Nonempty_list.t
implements Preface_specs.MONAD
and introduces an interface to define Preface_specs.TRAVERSABLE
using Nonempty_list
as an iterable structure.
module Monad : Preface_specs.Traversable.API_OVER_MONAD with type 'a t = 'a t
module Comonad : Preface_specs.COMONAD with type 'a t = 'a t
module Foldable : Preface_specs.FOLDABLE with type 'a t = 'a t
module Invariant : Preface_specs.INVARIANT with type 'a t = 'a t
By setting the inner type
type of Nonempty_list.t
it is possible to get implementations for abstractions without type parameter.
module Semigroup
(T : Preface_specs.Types.T0) :
Preface_specs.SEMIGROUP with type t = T.t t
Additional functions to facilitate practical work with Nonempty_list.t
.
val pure : 'a -> 'a t
Create a value from 'a
to 'a t
.
val create : 'a -> '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.
val hd : 'a t -> 'a
Returns the head of a non-empty list.
val length : 'a t -> int
Returns the length of a non-empty list.
rev_append a b
is a tail-recursive version of append (rev a) b
.
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 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 pp :
(Stdlib.Format.formatter -> 'a -> unit) ->
Stdlib.Format.formatter ->
'a t ->
unit
Formatter for pretty-printing for Nonempty_list.t
.