Module CCFun
Basic Functions
val compose_binop : ('a -> 'b) -> ('b -> 'b -> 'c) -> 'a -> 'a -> 'ccompose_binop f gisfun x y -> g (f x) (f y). Example (partial order):List.sort (compose_binop fst CCInt.compare) [1, true; 2, false; 1, false].- since
 - 0.6
 
val const : 'a -> 'b -> 'aProduce a function that just returns its first argument.
const x y = xfor anyy.
val curry : (('a * 'b) -> 'c) -> 'a -> 'b -> 'cConvert a function which accepts a pair of arguments into a function which accepts two arguments.
curry f x yisf (x,y).
val uncurry : ('a -> 'b -> 'c) -> ('a * 'b) -> 'cConvert a function which accepts a two arguments into a function which accepts a pair of arguments.
uncurry f (x,y)isf x y.
val tap : ('a -> _) -> 'a -> 'atap f xevaluatesf x, discards it, then returnsx. Useful in a pipeline, for instance:CCArray.(1 -- 10) |> tap CCArray.shuffle |> tap @@ CCArray.sort Pervasives.compare
val lexicographic : ('a -> 'a -> int) -> ('a -> 'a -> int) -> 'a -> 'a -> intLexicographic combination of comparison functions.
val finally : h:(unit -> _) -> f:(unit -> 'a) -> 'afinally h fcallsf ()and returns its result. If it raises, the same exception is raised; in any case,h ()is called afterf ()terminates.
val finally1 : h:(unit -> _) -> ('a -> 'b) -> 'a -> 'bfinally1 ~h f xis the same asf x, but after the computation,h ()is called whetherf xrose an exception or not.- since
 - 0.16
 
val finally2 : h:(unit -> _) -> ('a -> 'b -> 'c) -> 'a -> 'b -> 'cfinally2 ~h f x yis the same asf x y, but after the computation,h ()is called whetherf x yrose an exception or not.- since
 - 0.16
 
val opaque_identity : 'a -> 'aopaque_identity xis likex, but prevents Flambda from usingx's definition for optimizing it. (flambda is an optimization/inlining pass in OCaml >= 4.03).- since
 - 0.18
 
val iterate : int -> ('a -> 'a) -> 'a -> 'aiterate n fisfiteratedntimes. That is to say,iterate 0 f xisx,iterate 1 f xisf x,iterate 2 f xisf (f x), etc.- since
 - 2.1
 
Monad
Functions with a fixed domain are monads in their codomain.