package base

  1. Overview
  2. Docs
Module type
Class type

Various combinators for compare and equal functions.

val lexicographic : ('a -> 'a -> int) list -> 'a -> 'a -> int

lexicographic cmps x y compares x and y lexicographically using functions in the list cmps.

val lift : ('a -> 'a -> 'result) -> f:('b -> 'a) -> 'b -> 'b -> 'result

lift cmp ~f x y compares x and y by comparing f x and f y via cmp.

val reverse : ('a -> 'a -> 'result) -> 'a -> 'a -> 'result

reverse cmp x y = cmp y x

Reverses the direction of asymmetric relations by swapping their arguments. Useful, e.g., for relations implementing "is a subset of" or "is a descendant of".

Where reversed relations are already provided, use them directly. For example, Comparable.S provides ascending and descending, which are more readable as a pair than compare and reverse compare. Similarly, <= is more idiomatic than reverse (>=).

type 'a reversed = 'a

reversed is the identity type but its associated compare function is the same as the reverse function above. It allows you to get reversed comparisons with ppx_compare, writing, for example, [%compare: string Comparable.reversed] to have strings ordered in the reverse order.

val compare_reversed : ('a -> 'a -> int) -> 'a reversed -> 'a reversed -> int

The functions below are analogues of the type-specific functions exported by the Comparable.S interface.

val equal : ('a -> 'a -> int) -> 'a -> 'a -> bool
val max : ('a -> 'a -> int) -> 'a -> 'a -> 'a
val min : ('a -> 'a -> int) -> 'a -> 'a -> 'a

Innovation. Community. Security.