UNPKG

effect-ts-laws

Version:
38 lines 1.28 kB
/** * `@effect/typeclass` instances for the `fast-check` Arbitrary type. * @module */ import { Covariant as CO } from '@effect/typeclass'; import { dual } from 'effect/Function'; import fc from 'fast-check'; import { testUnaryEquivalence } from './equivalence.js'; const map = dual(2, (self, f) => self.map(a => f(a))); const flatMap = dual(2, (self, f) => self.chain(a => f(a))); /** * Monad instance for `fc.Arbitrary`. * @category fast-check */ export const Monad = { map, imap: CO.imap(map), flatMap, of: fc.constant, }; /** * Get an equivalence for `fc.Arbitrary<A>` from an equivalence of `A`. * Arbitraries are equal if they produce the same values for the same seeds. * Note this only means we were unable to find a counterexample to the * equivalence. * @category fast-check */ export const getEquivalence = (equalsA, parameters) => { const sample = (arbitrary) => (seed) => { const [result] = fc.sample(arbitrary, { seed, numRuns: 1 }); /* v8 ignore next 1 */ if (result === undefined) throw new Error('Could not sample.'); return result; }; return (self, that) => testUnaryEquivalence(fc.integer(), equalsA, parameters)(sample(self), sample(that)); }; //# sourceMappingURL=instances.js.map