effect-ts-laws
Version:
effect-ts law testing using fast-check.
15 lines • 1.02 kB
JavaScript
import { addLawSets, Law, lawTests } from '#law';
import { Covariant as optionInvariant } from '@effect/typeclass/data/Option';
import { flow, identity, pipe } from 'effect';
import { withOuterOption } from './compose.js';
import { unfoldGiven } from './given.js';
/**
* Typeclass laws for `Invariant`.
* @category typeclass laws
*/
export const invariantLaws = (given, suffix) => pipe(buildLaws(`Invariant${suffix ?? ''}`, given), addLawSets(buildLaws(...withOuterOption('Invariant', given, optionInvariant))));
const buildLaws = (name, given) => {
const { F: { imap }, fa, equalsFa, equalsFc, ab, bc, ba, cb, } = unfoldGiven(given);
return lawTests(name, Law('identity', 'imap(id, id) = id', fa)(a => equalsFa(imap(a, identity, identity), a)), Law('composition', 'a ▹ imap(ab, ba) ▹ imap(bc, cb) = a ▹ imap(bc ∘ ab, ba ∘ cb)', fa, ab, bc, ba, cb)((a, ab, bc, ba, cb) => equalsFc(pipe(a, imap(ab, ba), imap(bc, cb)), pipe(a, imap(flow(ab, bc), flow(cb, ba))))));
};
//# sourceMappingURL=Invariant.js.map