package travesty

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

Associative-list extensions.

type ('k, 'v) t = ('k, 'v) Base.List.Assoc.t

Defined to let this module be used directly in chaining operations etc.

Associative lists are bi-traversable (and therefore bi-mappable); the left type is keys, and the right type is values.

Here is an example of bi-mapping:

bi_map
  [("foo", 27); ("bar", 53); ("baz", 99)]
  ~left:String.capitalize ~right:Int.neg

(* returns: [("Foo", -27); ("Bar", -53); ("Baz", -99)] *)
include Travesty.Bi_traversable_types.S2 with type ('l, 'r) t := ('l, 'r) t
include Base.T2 with type ('l, 'r) t := ('l, 'r) t
include Travesty.Bi_traversable_types.Generic with type ('l, 'r) t := ('l, 'r) t and type 'l left := 'l and type 'r right := 'r
include Travesty.Generic_types.Bi_generic with type ('l, 'r) t := ('l, 'r) t with type 'l left := 'l with type 'r right := 'r

We can do non-monadic bi-mapping operations.

include Travesty.Bi_mappable_types.Generic with type ('l, 'r) t := ('l, 'r) t and type 'l left := 'l and type 'r right := 'r
include Travesty.Bi_mappable_types.Basic_generic with type ('l, 'r) t := ('l, 'r) t with type 'l left := 'l with type 'r right := 'r
include Travesty.Generic_types.Bi_generic with type ('l, 'r) t := ('l, 'r) t with type 'l left := 'l with type 'r right := 'r
val bi_map : ('l1, 'r1) t -> left:('l1 -> 'l2) -> right:('r1 -> 'r2) -> ('l2, 'r2) t

bi_map c ~left ~right maps left over every 'l1 left, and right over every 'r1 right, in c.

val map_left : ('l1, 'r) t -> f:('l1 -> 'l2) -> ('l2, 'r) t

map_left c ~f maps f over the left type of c only.

val map_right : ('l, 'r1) t -> f:('r1 -> 'r2) -> ('l, 'r2) t

map_right c ~f maps f over the right type of c only.

module On (M : Base.Applicative.S) : Travesty.Bi_traversable_types.Generic_on_applicative with type ('l, 'r) t := ('l, 'r) t and type 'l left := 'l and type 'r right := 'r and module M := M

On implements bi-traversal operators for a given applicative functor M.

module On_monad (M : Base.Monad.S) : Travesty.Bi_traversable_types.Generic_on_applicative with type ('l, 'r) t := ('l, 'r) t and type 'l left := 'l and type 'r right := 'r and module M := Travesty.Monad_exts.App(M)

On_monad implements bi-traversal operators for a given monad M.

module With_errors : Travesty.Bi_traversable_types.Generic_on_applicative with type ('l, 'r) t := ('l, 'r) t and type 'l left := 'l and type 'r right := 'r and module M := Base.Or_error

With_errors specialises On_monad to the error_monad.

val compose : ('a, 'b) t -> ('b, 'c) t -> equal:('b -> 'b -> bool) -> ('a, 'c) t

compose a b ~equal produces an associative list that returns (x, z) for each (x, y) in a such that a (y', z) exists in b, and equal y y' is true.

OCaml

Innovation. Community. Security.