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