effect-ts-laws
Version:
effect-ts law testing using fast-check.
28 lines • 1.24 kB
JavaScript
import { Array as AR, pipe, Tuple as TU } from 'effect';
import { buildConcreteTypeclassLaws } from './concrete/catalog.js';
import { buildParameterizedTypeclassLaws, isParameterizedTypeclassName, } from './parameterized/catalog.js';
/**
* Build typeclass laws for the given instances of some datatype.
* Any instances of typeclasses with laws can be tested, concrete or
* parameterized.
* @category harness
*/
export const buildTypeclassLawsFor = (instances, given) => {
const [concrete, parameterized] = pipe(Object.entries(instances), AR.partition(([typeclass]) => isParameterizedTypeclassName(typeclass)), TU.mapBoth({
onFirst: entries => Object.fromEntries(entries),
onSecond: entries => Object.fromEntries(entries),
}));
const { getEquivalence, equalsA, getArbitrary, a } = given;
return [
...(Object.keys(concrete).length !== 0
? buildConcreteTypeclassLaws(concrete, {
a: getArbitrary(a),
equalsA: getEquivalence(equalsA),
})
: []),
...(Object.keys(parameterized).length !== 0
? buildParameterizedTypeclassLaws()(parameterized, given)
: []),
];
};
//# sourceMappingURL=build.js.map