CCFun
include module type of CCShimsFun_
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]
.
curry f x y
is f (x,y)
. Convert a function which accepts a pair of arguments into a function which accepts two arguments.
uncurry f (x,y)
is f x y
. Convert a function which accepts a two arguments into a function which accepts a pair of arguments.
tap f x
evaluates f x
, discards it, then returns x
. Useful in a pipeline, for instance:
CCArray.(1 -- 10)
|> tap CCArray.shuffle
|> tap @@ CCArray.sort Stdlib.compare
Lexicographic combination of comparison functions.
finally ~h f
calls f ()
and returns its result. If it raises, the same exception is raised; in any case, h ()
is called after f ()
terminates. If h ()
raises an exception, then this exception will be passed on and any exception that may have been raised by f ()
is lost.
finally1 ~h f x
is the same as f x
, but after the computation, h ()
is called whether f x
rose an exception or not. If h ()
raises an exception, then this exception will be passed on and any exception that may have been raised by f ()
is lost.
finally2 ~h f x y
is the same as f x y
, but after the computation, h ()
is called whether f x y
rose an exception or not. If h ()
raises an exception, then this exception will be passed on and any exception that may have been raised by f ()
is lost.
opaque_identity x
is like x
, but prevents Flambda from using x
's definition for optimizing it. (flambda is an optimization/inlining pass in OCaml >= 4.03).
iterate n f
is f
iterated n
times. That is to say, iterate 0 f x
is x
, iterate 1 f x
is f x
, iterate 2 f x
is f (f x)
, etc.
Infix operators.
module Infix : sig ... end
include module type of Infix
(f %> g) x
or (%>) f g x
is g (f x)
. Alias to compose
.
Functions with a fixed domain are monads in their codomain.