mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
more functions in CCPair
This commit is contained in:
parent
462ac72b2e
commit
5dc0155ab0
2 changed files with 32 additions and 0 deletions
|
|
@ -36,6 +36,11 @@ let map f g (x,y) = f x, g y
|
|||
|
||||
let map_same f (x,y) = f x, f y
|
||||
|
||||
let map_fst f (x,_) = f x
|
||||
let map_snd f (_,x) = f x
|
||||
|
||||
let iter f (x,y) = f x y
|
||||
|
||||
let swap (x,y) = y, x
|
||||
|
||||
let (<<<) = map1
|
||||
|
|
@ -47,6 +52,10 @@ let ( *** ) = map
|
|||
let ( &&& ) f g x = f x, g x
|
||||
|
||||
let merge f (x,y) = f x y
|
||||
let fold = merge
|
||||
|
||||
let dup x = x,x
|
||||
let dup_map f x = x, f x
|
||||
|
||||
let equal f g (x1,y1) (x2,y2) = f x1 x2 && g y1 y2
|
||||
|
||||
|
|
|
|||
|
|
@ -36,6 +36,16 @@ val map : ('a -> 'c) -> ('b -> 'd) -> ('a * 'b) -> ('c * 'd)
|
|||
|
||||
val map_same : ('a -> 'b) -> ('a*'a) -> ('b*'b)
|
||||
|
||||
val map_fst : ('a -> 'b) -> ('a * _) -> 'b
|
||||
(** Compose the given function with [fst].
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val map_snd : ('a -> 'b) -> (_ * 'a) -> 'b
|
||||
(** Compose the given function with [snd].
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val iter : ('a -> 'b -> unit) -> ('a * 'b) -> unit
|
||||
|
||||
val swap : ('a * 'b) -> ('b * 'a)
|
||||
(** Swap the components of the tuple *)
|
||||
|
||||
|
|
@ -55,6 +65,19 @@ val ( &&& ) : ('a -> 'b) -> ('a -> 'c) -> 'a -> ('b * 'c)
|
|||
val merge : ('a -> 'b -> 'c) -> ('a * 'b) -> 'c
|
||||
(** Uncurrying (merges the two components of a tuple) *)
|
||||
|
||||
val fold : ('a -> 'b -> 'c) -> ('a * 'b) -> 'c
|
||||
(** Synonym to {!merge}
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val dup : 'a -> ('a * 'a)
|
||||
(** [dup x = (x,x)] (duplicate the value)
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val 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 NEXT_RELEASE *)
|
||||
|
||||
val equal : ('a -> 'a -> bool) -> ('b -> 'b -> bool) -> ('a * 'b) -> ('a * 'b) -> bool
|
||||
|
||||
val compare : ('a -> 'a -> int) -> ('b -> 'b -> int) -> ('a * 'b) -> ('a * 'b) -> int
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue