package travesty

  1. Overview
  2. Docs
Monadically traversable containers

Install

Dune Dependency

Authors

Maintainers

Sources

travesty-v0.3.0.tbz
sha256=40ada5c475cfeba7d933eec133294d1b5ef5da6ce864c9746b2ce4ce49b5e3a4
md5=dc818d6b232f13edb388d25781cd99a2

doc/travesty/Travesty/T_fn/index.html

Module Travesty.T_fnSource

Miscellaneous function combinators.

T_fn contains various higher-order functions in the style of Core_kernel's Fn module.

Sourceval on : ('a -> 'b) -> ('b -> 'b -> 'r) -> 'a -> 'a -> 'r

on lift 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.

Example:

  let ints = on fst    Int.equal (42, "banana") (42, "apple") in
  let strs = on snd String.equal (42, "banana") (42, "apple") in
  ints, strs (* --> true, false *)
Sourceval conj : ('a -> bool) -> ('a -> bool) -> 'a -> bool

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 (fun () -> true)  (fun () -> failwith "oops") (); (* --> exception *)
  conj (fun () -> false) (fun () -> failwith "oops") (); (* --> false *)
Sourceval disj : ('a -> bool) -> ('a -> bool) -> 'a -> bool

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 (fun () -> false) (fun () -> failwith "oops") (); (* --> exception *)
  disj (fun () -> true)  (fun () -> failwith "oops") (); (* --> false *)
OCaml

Innovation. Community. Security.