Traversable_types.Generic
Generic
is a generic interface for traversable containers, used to build S0
(arity-0) and S1
(arity-1).
include Generic_types.Generic
module On
(M : Base.Applicative.S) :
Generic_on_applicative
with type ('a, 'phantom) t := ('a, 'phantom) t
and type 'a elt := 'a elt
and module M := M
On
implements traversal operators for a given applicative M
.
module On_monad
(M : Base.Monad.S) :
Generic_on_monad
with type ('a, 'phantom) t := ('a, 'phantom) t
and type 'a elt := 'a elt
and module M := M
On_monad
implements traversal operators for a given monad M
. Compared to On(Monad_exts.App(M))
, this adds various derived operators available only for monads.
We can do generic container operations.
We can do non-applicative mapping operations.
include Mappable_types.Generic
with type ('a, 'phantom) t := ('a, 'phantom) t
and type 'a elt := 'a elt
Generic
refers to the container type as 'a t
, and the element type as 'a elt
; substitute t
/elt
(arity-0) or 'a t
/'a
(arity-1) accordingly below.
include Generic_types.Generic
with type ('a, 'phantom) t := ('a, 'phantom) t
with type 'a elt := 'a elt
val fold_map :
('a, 'phantom) t ->
f:('acc -> 'a elt -> 'acc * 'b elt) ->
init:'acc ->
'acc * ('b, 'phantom) t
fold_map c ~f ~init
folds f
over every t
in c
, threading through an accumulator with initial value init
.
mapi ~f t
maps f
across t
, passing in an increasing position counter.
module With_errors :
Generic_on_monad
with type ('a, 'phantom) t := ('a, 'phantom) t
and type 'a elt := 'a elt
and module M := Base.Or_error
With_errors
specialises On_applicative
to the error applicative.