package travesty
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=9c7b3803620c54496a35983285242ec8e06a5efb1baa3523384d7184b7e9fab7
sha512=991646fe5bb899971d3f8c00432d4df6c45dbd81cbff885b28d30d9c228e5df61f1e8d61aadc164ec35c448093abb34fd7a7d571e1cdf4d3af25579bf400f167
doc/travesty.base_exts/Travesty_base_exts/Fn/index.html
Module Travesty_base_exts.Fn
Miscellaneous function combinators.
Fn
contains various higher-order functions in the style of Base's Fn
module.
Constant predicates
These are convenience shorthands for Base.Fn.const
.
Pointwise liftings of operators
These complement Base.Fn.non
.
conj f g
lifts &&
over predicates f
and g
. It is short-circuiting: g
is never called if f
returns false.
Examples:
let is_zero = Int.(conj is_non_negative is_non_positive)
(* Short-circuiting: *)
conj always (fun () -> failwith "oops") () ;
(* --> exception *)
conj never (fun () -> failwith "oops") ()
(* --> false *)
disj f g
lifts ||
over predicates f
and g
. It is short-circuiting: g
is never called if f
returns true.
Examples:
let is_not_zero = Int.(disj is_negative is_positive)
(* Short-circuiting: *)
disj never (fun () -> failwith "oops") () ;
(* --> exception *)
disj always (fun () -> failwith "oops") ()
(* --> false *)
Miscellaneous combinators
on lift x y ~f
lifts a binary function f
using the lifter lift
. It does the same thing as the `on` function from Haskell, but with arguments flipped to make sense without infixing.
Effectively, it's Base.Comparable.lift
, but with a slightly different signature.
Example:
let ints = on fst ~f:Int.equal (42, "banana") (42, "apple") in
let strs = on snd ~f:String.equal (42, "banana") (42, "apple") in
(ints, strs)
(* --> true, false *)
F# style function composition operator
This is in a separate module to reduce the ambiguity caused by its use.
module Compose_syntax : sig ... end