mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-07 03:35:30 -05:00
additional utils for pairs and functions
This commit is contained in:
parent
a8dc42024b
commit
d9ccb619a1
4 changed files with 28 additions and 0 deletions
|
|
@ -30,6 +30,12 @@ let (|>) x f = f x
|
|||
|
||||
let compose f g x = g (f x)
|
||||
|
||||
let flip f x y = f y x
|
||||
|
||||
let curry f x y = f (x,y)
|
||||
|
||||
let uncurry f (x,y) = f x y
|
||||
|
||||
let (%>) = compose
|
||||
|
||||
let (%) f g x = f (g x)
|
||||
|
|
|
|||
|
|
@ -35,6 +35,13 @@ val compose : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c
|
|||
val (%>) : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c
|
||||
(** Alias to [compose] *)
|
||||
|
||||
val flip : ('a -> 'b -> 'c) -> 'b -> 'a -> 'c
|
||||
(** flip arguments *)
|
||||
|
||||
val curry : ('a * 'b -> 'c) -> 'a -> 'b -> 'c
|
||||
|
||||
val uncurry : ('a -> 'b -> 'c) -> ('a * 'b) -> 'c
|
||||
|
||||
val (%) : ('b -> 'c) -> ('a -> 'b) -> 'a -> 'c
|
||||
(** Mathematical composition *)
|
||||
|
||||
|
|
|
|||
|
|
@ -44,6 +44,10 @@ let (>>>) = map2
|
|||
|
||||
let ( *** ) = map
|
||||
|
||||
let ( &&& ) f g x = f x, g x
|
||||
|
||||
let merge f (x,y) = f x y
|
||||
|
||||
let equal f g (x1,y1) (x2,y2) = f x1 x2 && g y1 y2
|
||||
|
||||
let compare f g (x1,y1) (x2,y2) =
|
||||
|
|
|
|||
|
|
@ -37,12 +37,23 @@ val map : ('a -> 'c) -> ('b -> 'd) -> ('a * 'b) -> ('c * 'd)
|
|||
val map_same : ('a -> 'b) -> ('a*'a) -> ('b*'b)
|
||||
|
||||
val swap : ('a * 'b) -> ('b * 'a)
|
||||
(** Swap the components of the tuple *)
|
||||
|
||||
val (<<<) : ('a -> 'b) -> ('a * 'c) -> ('b * 'c)
|
||||
(** Map on the left side of the tuple *)
|
||||
|
||||
val (>>>) : ('a -> 'b) -> ('c * 'a) -> ('c * 'b)
|
||||
(** Map on the right side of the tuple *)
|
||||
|
||||
val ( *** ) : ('a -> 'c) -> ('b -> 'd) -> ('a * 'b) -> ('c * 'd)
|
||||
(** Map on both sides of a tuple *)
|
||||
|
||||
val ( &&& ) : ('a -> 'b) -> ('a -> 'c) -> 'a -> ('b * 'c)
|
||||
(** [f &&& g] is [fun x -> f x, g x]. It splits the computations into
|
||||
two parts *)
|
||||
|
||||
val merge : ('a -> 'b -> 'c) -> ('a * 'b) -> 'c
|
||||
(** Uncurrying (merges the two components of a tuple) *)
|
||||
|
||||
val equal : ('a -> 'a -> bool) -> ('b -> 'b -> bool) -> ('a * 'b) -> ('a * 'b) -> bool
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue