UNPKG

effect-ts-laws

Version:
71 lines 2.66 kB
import { option, predicate, stringKeyRecord, testPredicateEquivalence, testUnaryEquivalence, tinyInteger, } from '#arbitrary'; import { MonoidSum } from '@effect/typeclass/data/Number'; import { getOptionalMonoid } from '@effect/typeclass/data/Option'; import { Number as NU, Record as RC } from 'effect'; import { constant } from 'effect/Function'; import { getEquivalence, getOrder } from 'effect/Option'; import { unfoldMonomorphicGiven } from './given.js'; /** * An arbitrary for the underlying type of the * {@link vitest.testTypeclassLaws} unit under test. * @category monomorphic */ export const monoArbitrary = option(tinyInteger); /** * Arbitrary for a record with string keys and `Mono` values. * @category monomorphic */ export const monoRecordArbitrary = stringKeyRecord(monoArbitrary); /** @category monomorphic */ export const monoPredicateArbitrary = predicate(); /** * The equivalence used for {@link vitest.testTypeclassLaws}. * @category monomorphic */ export const monoEquivalence = getEquivalence(NU.Equivalence); /** * Equivalence for a record with string keys and `Mono` values. * @category monomorphic */ export const monoRecordEquivalence = RC.getEquivalence(monoEquivalence); /** * The order used for {@link vitest.testTypeclassLaws}. * @category monomorphic */ export const monoOrder = getOrder(NU.Order); /** * Monoid instance for the `Mono` type. * @category monomorphic */ export const monoMonoid = getOptionalMonoid(MonoidSum); /** * Build a sampling equivalence between functions of type * `(numArray: Mono) ⇒ A`. * @category monomorphic */ export const getMonoUnaryEquivalence = (equalsA) => testUnaryEquivalence(monoArbitrary, equalsA); /** * Build a sampling equivalence for predicates of the underlying `Mono` type. * @category monomorphic */ export const monoPredicateEquivalence = testPredicateEquivalence(monoArbitrary); /** * Unfold the options for monomorphic typeclass law tests on the underlying type * `Mono` from a function that will lift equivalence in the higher-kinded type * under test, and one that will lift an arbitrary. This function is used inside * typeclass law test code to unfold the requirements of their law predicates. * @category monomorphic */ export const unfoldMonoGiven = (getEquivalence, getArbitrary) => unfoldMonomorphicGiven({ a: monoArbitrary, equalsA: monoEquivalence, Monoid: monoMonoid, getEquivalence, getArbitrary, }); const contravariant = (F) => ({ F, ...unfoldMonoGiven(constant(monoPredicateEquivalence), ((_) => monoPredicateArbitrary)), }); unfoldMonoGiven.contravariant = contravariant; //# sourceMappingURL=mono.js.map