effect-ts-laws
Version:
effect-ts law testing using fast-check.
17 lines • 833 B
JavaScript
import { Law } from '#law';
/**
* Test that a binary operation is associative.
* @category algebraic laws
*/
export const associativity = ({ f, a, equals, }, note = '(a ⊕ b) ⊕ c = a ⊕ (b ⊕ c)', name = 'associativity') => Law(name, note, a, a, a)((a, b, c) => equals(f(f(a, b), c), f(a, f(b, c))));
/**
* Test the composition of two operations cancels each other.
* @category algebraic laws
*/
export const inverse = ({ f, g, a, equals, }, note = 'g ⚬ f = id', name = 'inverse') => Law(name, note, a)(a => equals(g(f(a)), a));
/**
* Test that a binary operation is symmetric.
* @category algebraic laws
*/
export const symmetry = ({ f, a, equals, }, note = 'f(a, b) = f(b, a)', name = 'symmetry') => Law(name, note, a, a)((left, right) => equals(f(left, right), f(right, left)));
//# sourceMappingURL=algebra.js.map