package containers

  1. Overview
  2. Docs
A modular, clean and powerful extension of the OCaml standard library

Install

dune-project
 Dependency

Authors

Maintainers

Sources

containers-3.18.tbz
sha256=52eeff91ce42b52305e6aaa8a58b88ce8f0a5a984199e59ca7e2fd9ebabe61d7
sha512=dc7337e6cbc9850542c7c9228d3bcb4e4add57a55e2a2992f21fb4761b3e10a68ef1d57ca37a7f5b303fc875fe3df5ecb69dbf2930bfcd1561ce03f7ae83e24b

doc/containers/CCPair/index.html

Module CCPairSource

Tuple Functions

Pairs

Sourcetype ('a, 'b) t = 'a * 'b

The type for pairs.

Sourceval make : 'a -> 'b -> 'a * 'b

make a b is the pair (a, b).

Sourceval fst : ('a * 'b) -> 'a

fst (a, b) is a.

Sourceval snd : ('a * 'b) -> 'b

snd (a, b) is b.

Sourceval swap : ('a * 'b) -> 'b * 'a

swap (a, b) is (b, a).

Iterators

Sourceval fold : ('a -> 'b -> 'c) -> ('a * 'b) -> 'c

fold f (a, b) applies f to a and b.

Sourceval map : ('a -> 'c) -> ('b -> 'd) -> ('a * 'b) -> 'c * 'd

map f g (a, b) applies f to a and g to b.

Sourceval iter : ('a -> unit) -> ('b -> unit) -> ('a * 'b) -> unit

iter f g (a, b) first applies f to a, and then g to b.

Sourceval map_fst : ('a -> 'c) -> ('a * 'b) -> 'c * 'b

map_fst f p applies f to p's first component.

Sourceval map_snd : ('b -> 'c) -> ('a * 'b) -> 'a * 'c

map_snd f p applies f to p's second component.

Predicates and comparisons

Sourceval equal : ('a -> 'a -> bool) -> ('b -> 'b -> bool) -> ('a * 'b) -> ('a * 'b) -> bool

equal eqa eqb (a1, b1) (a2, b2) is true if and only if eqa a1 a2 and eqb b1 b2 are both true.

Sourceval compare : ('a -> 'a -> int) -> ('b -> 'b -> int) -> ('a * 'b) -> ('a * 'b) -> int

compare cmpa cmpb is a total order on pairs using cmpa to compare the first component, and cmpb to compare the second component. It is implemented by a lexicographic order.

Sourceval map_same : ('a -> 'b) -> ('a * 'a) -> 'b * 'b

Like map but specialized for pairs with elements of the same type.

Sourceval map2 : ('a1 -> 'b1 -> 'c1) -> ('a2 -> 'b2 -> 'c2) -> ('a1 * 'a2) -> ('b1 * 'b2) -> 'c1 * 'c2

map2 f g (a,b) (x,y) return (f a x, g b y).

  • since 3.0
Sourceval map_same2 : ('a -> 'b -> 'c) -> ('a * 'a) -> ('b * 'b) -> 'c * 'c

map_same2 f (a,b) (x,y) return (f a x, f b y).

  • since 3.0
Sourceval fst_map : ('a -> 'b) -> ('a * _) -> 'b

Compose the given function with fst. Rename from map_fst since 3.0.

  • since 0.3.3
Sourceval snd_map : ('a -> 'b) -> (_ * 'a) -> 'b

Compose the given function with snd. Rename from map_snd since 3.0.

  • since 0.3.3
Sourceval (<<<) : ('a -> 'b) -> ('a * 'c) -> 'b * 'c

Map on the left side of the tuple.

Sourceval (>>>) : ('a -> 'b) -> ('c * 'a) -> 'c * 'b

Map on the right side of the tuple.

Sourceval (***) : ('a -> 'c) -> ('b -> 'd) -> ('a * 'b) -> 'c * 'd

Map on both sides of a tuple.

Sourceval (&&&) : ('a -> 'b) -> ('a -> 'c) -> 'a -> 'b * 'c

f &&& g is fun x -> f x, g x. It splits the computations into two parts.

Sourceval merge : ('a -> 'b -> 'c) -> ('a * 'b) -> 'c

Uncurrying (merges the two components of a tuple).

Sourceval dup : 'a -> 'a * 'a

dup x = (x,x) (duplicate the value).

  • since 0.3.3
Sourceval dup_map : ('a -> 'b) -> 'a -> 'a * 'b

dup_map f x = (x, f x). Duplicates the value and applies the function to the second copy.

  • since 0.3.3
Sourceval to_string : ?sep:string -> ('a -> string) -> ('b -> string) -> ('a * 'b) -> string

Print tuple in a string

  • since 2.7
Sourcetype 'a printer = Format.formatter -> 'a -> unit
Sourceval pp : ?pp_start:unit printer -> ?pp_stop:unit printer -> ?pp_sep:unit printer -> 'a printer -> 'b printer -> ('a * 'b) printer

Print a pair given an optional separator, an optional start and stop and a method for printing each of its elements.