Module type 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
type ('a, 'phantom) t

Placeholder for the container type.

type 'a elt

Placeholder for the type of elements inside the container.

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.

include Base.Container.Generic with type ('a, 'phantom) t := ('a, 'phantom) t and type 'a elt := 'a elt
val length : ('a, 'b) t -> int
val is_empty : ('a, 'b) t -> bool
val mem : ('a, 'b) t -> 'a elt -> equal:('a elt -> 'a elt -> bool) -> bool
val iter : ('a, 'b) t -> f:('a elt -> unit) -> unit
val fold : ('a, 'b) t -> init:'acc -> f:('acc -> 'a elt -> 'acc) -> 'acc
val fold_result : ('a, 'b) t -> init:'acc -> f:('acc -> 'a elt -> ('acc, 'e) Base__.Result.t) -> ('acc, 'e) Base__.Result.t
val fold_until : ('a, 'b) t -> init:'acc -> f:('acc -> 'a elt -> ('acc, 'final) Base__Container_intf.Continue_or_stop.t) -> finish:('acc -> 'final) -> 'final
val exists : ('a, 'b) t -> f:('a elt -> bool) -> bool
val for_all : ('a, 'b) t -> f:('a elt -> bool) -> bool
val count : ('a, 'b) t -> f:('a elt -> bool) -> int
val sum : (module Base__Container_intf.Summable with type t = 'sum) -> ('a, 'b) t -> f:('a elt -> 'sum) -> 'sum
val find : ('a, 'b) t -> f:('a elt -> bool) -> 'a elt option
val find_map : ('a, 'c) t -> f:('a elt -> 'b option) -> 'b option
val to_list : ('a, 'b) t -> 'a elt list
val to_array : ('a, 'b) t -> 'a elt array
val min_elt : ('a, 'b) t -> compare:('a elt -> 'a elt -> int) -> 'a elt option
val max_elt : ('a, 'b) t -> compare:('a elt -> 'a elt -> int) -> 'a elt option

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 map : ('a, 'phantom) t -> f:('a elt -> 'b elt) -> ('b, 'phantom) t

map c ~f maps f over every t in c.

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.

val mapi : f:(Base.int -> 'a elt -> 'b elt) -> ('a, 'phantom) t -> ('b, 'phantom) t

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.