From af850a88c163dbe644e89422430277e799e8fb8e Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Wed, 19 Nov 2014 14:49:51 +0100 Subject: [PATCH] CCFun.on_top_of (binary composition) --- core/CCFun.cppo.ml | 2 ++ core/CCFun.mli | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/core/CCFun.cppo.ml b/core/CCFun.cppo.ml index 49e2fada..e9568b35 100644 --- a/core/CCFun.cppo.ml +++ b/core/CCFun.cppo.ml @@ -40,6 +40,8 @@ let (@@) f x = f x let compose f g x = g (f x) +let compose_binop f g x y = g (f x) (f y) + let flip f x y = f y x let curry f x y = f (x,y) diff --git a/core/CCFun.mli b/core/CCFun.mli index 6ac21173..2d7ab372 100644 --- a/core/CCFun.mli +++ b/core/CCFun.mli @@ -32,6 +32,12 @@ val (|>) : 'a -> ('a -> 'b) -> 'b val compose : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c (** Composition *) +val compose_binop : ('a -> 'b) -> ('b -> 'b -> 'c) -> 'a -> 'a -> 'c +(** [compose_binop f g] is [fun x y -> g (f x) (f y)] + Example (partial order): + [List.sort (compose_binop fst CCInt.compare) [1, true; 2, false; 1, false]] + @since NEXT_RELEASE*) + val (%>) : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c (** Alias to [compose] *) @@ -68,9 +74,9 @@ val lexicographic : ('a -> 'a -> int) -> ('a -> 'a -> int) -> 'a -> 'a -> int (** Lexicographic combination of comparison functions *) val finally : h:(unit -> unit) -> f:(unit -> 'a) -> 'a - (** [finally h f] calls [f ()] and returns its result. If it raises, the - same exception is raised; in {b any} case, [h ()] is called after - [f ()] terminates. *) +(** [finally h f] calls [f ()] and returns its result. If it raises, the + same exception is raised; in {b any} case, [h ()] is called after + [f ()] terminates. *) (** {2 Monad}