Module Relude_Eq
let by: a b. ('b => 'a) => eq('a) => eq('b);
Eq.by
creates aneq('b)
function from aneq('a)
and a function from'b => 'a
. Effectively, this allows you to say "my complex type can be compared for equality because I'm already able to compare these simpler parts."This is the contravariant map for the
eq('a)
function.module User = { type t = { id: string, name: string }; // create an equality function for our user type by comparing its id. let equals: eq(t) = Eq.by(user => user.id, String.eq); }
let cmap: ('a => 'b) => eq('b) => eq('a);
Eq.cmap
is the contravariantmap
for the equals function. It is an alias forEq.by
.
module Contravariant: BsBastet.Interface.CONTRAVARIANT with type Contravariant.t('a) = eq('a);