Module CCFun
Basic Functions
include module type of CCShimsFun_
val compose_binop : ('a -> 'b) -> ('b -> 'b -> 'c) -> 'a -> 'a -> 'c
compose_binop f g
isfun 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 curry : (('a * 'b) -> 'c) -> 'a -> 'b -> 'c
curry f x y
isf (x,y)
. Convert a function which accepts a pair of arguments into a function which accepts two arguments.
val uncurry : ('a -> 'b -> 'c) -> ('a * 'b) -> 'c
uncurry f (x,y)
isf x y
. Convert a function which accepts a two arguments into a function which accepts a pair of arguments.
val tap : ('a -> _) -> 'a -> 'a
tap f x
evaluatesf x
, discards it, then returnsx
. Useful in a pipeline, for instance:CCArray.(1 -- 10) |> tap CCArray.shuffle |> tap @@ CCArray.sort Stdlib.compare
val lexicographic : ('a -> 'a -> int) -> ('a -> 'a -> int) -> 'a -> 'a -> int
Lexicographic combination of comparison functions.
val finally : h:(unit -> _) -> f:(unit -> 'a) -> 'a
finally ~h f
callsf ()
and returns its result. If it raises, the same exception is raised; in any case,h ()
is called afterf ()
terminates. Ifh ()
raises an exception, then this exception will be passed on and any exception that may have been raised byf ()
is lost.
val finally1 : h:(unit -> _) -> ('a -> 'b) -> 'a -> 'b
finally1 ~h f x
is the same asf x
, but after the computation,h ()
is called whetherf x
rose an exception or not. Ifh ()
raises an exception, then this exception will be passed on and any exception that may have been raised byf ()
is lost.- since
- 0.16
val finally2 : h:(unit -> _) -> ('a -> 'b -> 'c) -> 'a -> 'b -> 'c
finally2 ~h f x y
is the same asf x y
, but after the computation,h ()
is called whetherf x y
rose an exception or not. Ifh ()
raises an exception, then this exception will be passed on and any exception that may have been raised byf ()
is lost.- since
- 0.16
val opaque_identity : 'a -> 'a
opaque_identity x
is 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 -> 'a
iterate n f
isf
iteratedn
times. That is to say,iterate 0 f x
isx
,iterate 1 f x
isf x
,iterate 2 f x
isf (f x)
, etc.- since
- 2.1
Infix
Infix operators.
module Infix : sig ... end
include module type of Infix
Monad
Functions with a fixed domain are monads in their codomain.