package travesty

  1. Overview
  2. Docs
Traversable containers, monad extensions, and more

Install

Dune Dependency

Authors

Maintainers

Sources

travesty-v0.7.0.tbz
sha256=01661918f73f33b0e6d0cf3851c2d5d6ef76b86332a3e76a4958689ff1a6fd3a
sha512=14e9b0e9ae39055c386c5e996055ce59edf57b9bf9b0055722632520f9c9b0270af571576950be982ed2b86e859361c7344166a38a85fa7d28d45be8f3e18c77

doc/travesty.base_exts/Travesty_base_exts/Fn/index.html

Module Travesty_base_exts.FnSource

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.

Sourceval always : 'a -> bool

always x is true.

Sourceval never : 'a -> bool

never x is false.

Pointwise liftings of operators

These complement Base.Fn.non.

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 always (fun () -> failwith "oops") () ;
  (* --> exception *)
  conj never (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 never (fun () -> failwith "oops") () ;
  (* --> exception *)
  disj always (fun () -> failwith "oops") ()

  (* --> false *)
Sourceval (&&&) : ('a -> bool) -> ('a -> bool) -> 'a -> bool

f &&& g is conj f g.

Sourceval (|||) : ('a -> bool) -> ('a -> bool) -> 'a -> bool

f ||| g is disj f g.

Miscellaneous combinators

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

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.

Sourcemodule Compose_syntax : sig ... end
OCaml

Innovation. Community. Security.