Module Relude_Ord
Relude.Ord contains functions and sub-modules to help work with comparison functions that take two values of the same type and return a value of Bastet's ordering type.
type nonrec ordering= BsBastet.Interface.ordering;The ordering type represents the result of a comparison -
`less_than,`equal_to, or`greater_than.
type compare('a)= 'a => 'a => ordering;The compare function is the heart of the
Ordtype class.
let by: a b. ('b => 'a) => compare('a) => compare('b);Ord.byconverts an compare function for a type'ato a compare function of type'busing a function from'b => 'a.If we know how to compare
'as and we know how to convert'bto'a, we can compare'bs by first converting our'bs to'as, then comparing them with the'acompare function.This is the contravariant map for the compare function.
let userCompare: compare(user) = Ord.by(user => user.name, String.compare);
let cmap: ('a => 'b) => compare('b) => compare('a);Ord.cmapis an alias forbyand the foundational function of theContravarianttype class instance for thecomparefunction.
module Contravariant: BsBastet.Interface.CONTRAVARIANT with type Contravariant.t('a) = compare('a);include { ... };
let reverse: a. compare('a) => compare('a);Ord.reversecreates a new compare function that returns the opposite of the given compare function.
let compareAsIntBy: a. compare('a) => 'a => 'a => int;Ord.compareAsIntBycompares two values using the given compare function, returning1if the first value is greater than the second,-1if the first is less than the second, and0if they are equal.While not often needed in the Relude/Bastet ecosystem, this function may be useful for translating a Bastet-compatible
comparefunction to one that works with the rest of the OCaml world.
let compareAsInt: (module BsBastet.Interface.ORD with type t = 'a) => 'a => 'a => int;Compares two values using the given ORD module
let minBy: a. compare('a) => 'a => 'a => 'a;Finds the minimum of two values using the given compare function
let min: (module BsBastet.Interface.ORD with type t = 'a) => 'a => 'a => 'a;Finds the minimum of two values using the given ORD module
let maxBy: a. compare('a) => 'a => 'a => 'a;Finds the maximum of two values using the given compare function
let max: (module BsBastet.Interface.ORD with type t = 'a) => 'a => 'a => 'a;Finds the maximum of two values using the given ORD module
let lessThanBy: a. compare('a) => 'a => 'a => bool;Indicates if the item on the left is less than the item on the right using the given compare function.
let ltBy: compare('a) => 'a => 'a => bool;Ord.ltByis an alias forlessThanBy.
let lessThan: (module BsBastet.Interface.ORD with type t = 'a) => 'a => 'a => bool;Ord.lessThanindicates if the item on the left is less than the item on the right using the given ORD module.
let lt: (module BsBastet.Interface.ORD with type t = 'a) => 'a => 'a => bool;Ord.ltis an alias forlessThan.
let lessThanOrEqBy: a. compare('a) => 'a => 'a => bool;Ord.lessThanOrEqByindicates if the item on the left is less than or equal to the item on the right using the given compare function.
let lteBy: compare('a) => 'a => 'a => bool;Ord.lteByis an alias forlessThanOrEqBy.
let lessThanOrEq: (module BsBastet.Interface.ORD with type t = 'a) => 'a => 'a => bool;Ord.lessThanOrEqindicates if the item on the left is less than or equal to the item on the right using the given ORD module.
let lte: (module BsBastet.Interface.ORD with type t = 'a) => 'a => 'a => bool;Ord.lteis an alias forlessThanOrEq.
let greaterThanBy: a. compare('a) => 'a => 'a => bool;Ord.greaterThanByindicates if the item on the left is greater than the item on the right using the given compare function.
let gtBy: compare('a) => 'a => 'a => bool;Ord.gtByis an alias forgreaterThanBy.
let greaterThan: (module BsBastet.Interface.ORD with type t = 'a) => 'a => 'a => bool;Ord.greaterThanindicates if the item on the left is greater than the item on the right using the given ORD module.
let gt: (module BsBastet.Interface.ORD with type t = 'a) => 'a => 'a => bool;Ord.gtis an alias forgreaterThan.
let greaterThanOrEqBy: a. compare('a) => 'a => 'a => bool;Ord.greaterThanOrEqByindicates if the item on the left is greater than or equal to the item on the right using the given compare function.
let gteBy: compare('a) => 'a => 'a => bool;Ord.gteByis an alias forgreaterThanOrEqBy.
let greaterThanOrEq: (module BsBastet.Interface.ORD with type t = 'a) => 'a => 'a => bool;Ord.greaterThanOrEqindicates if the item on the left is greater than or equal to the item on the right using the given ORD module.
let gte: (module BsBastet.Interface.ORD with type t = 'a) => 'a => 'a => bool;Ord.gteis an alias forgreaterThanOrEq.
let clampBy: a. compare('a) => min:'a => max:'a => 'a => 'a;Ord.clampByensures a provided value falls between a max and min (inclusive).Note that if the provided min is greater than the provided max, the max is always returned. This is considered an incorrect use of
clamp.let clamp = clampBy(Int.compare); clamp(~min=0, ~max=5, 3) == 3; clamp(~min=0, ~max=5, 0) == 0; clamp(~min=0, ~max=3, 4) == 3; clamp(~min=1, ~max=0, 2) == 0; // don't do this
let clamp: (module BsBastet.Interface.ORD with type t = 'a) => min:'a => max:'a => 'a => 'a;Ord.clampis the first-class module version ofclampBy.
let betweenBy: a. compare('a) => min:'a => max:'a => 'a => bool;Ord.betweenBydetermines whether a provided value falls between a min and max.
let between: (module BsBastet.Interface.ORD with type t = 'a) => min:'a => max:'a => 'a => bool;Ord.betweenis the first-class module version ofbetweenBy.
let abs: (module BsBastet.Interface.ORD with type t = 'a) => (module BsBastet.Interface.RING with type t = 'a) => 'a => 'a;Ord.absdetermines the absolute value for any value that can be compared for ordering and implements Ring (specifically haszeroandsubtract). If the provided value is greater than (or equal to) zero, that value is returned, otherwise the negated version of that value is returned.