package travesty

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Generic is a generic interface for traversable containers, used to build S0 (arity-0) and S1 (arity-1).

include Types_intf.Generic
type 'a t

Placeholder for the container type.

type 'a elt

Placeholder for the type of elements inside the container.

module On_monad (M : Base.Monad.S) : Generic_on_monad with type 'a t := 'a t and type 'a elt := 'a elt and module M := M

On_monad implements monadic traversal operators for a given monad M.

We can do generic container operations.

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

We can do non-monadic mapping operations.

include Mappable.Generic with type 'a t := 'a 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 Types_intf.Generic with type 'a t := 'a t with type 'a elt := 'a elt
val map : 'a t -> f:('a elt -> 'b elt) -> 'b t

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

val fold_map : 'a t -> f:('acc -> 'a elt -> 'acc * 'b elt) -> init:'acc -> 'acc * 'b 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 t -> 'b t

mapi ~f t maps f across t, passing in an increasing position counter.

module With_errors : Generic_on_monad with type 'a t := 'a t and type 'a elt := 'a elt and module M := Base.Or_error

With_errors specialises On_monad to the error monad.

OCaml

Innovation. Community. Security.