UNPKG

effect-ts-laws

Version:
65 lines 2.24 kB
import { option } from '#arbitrary'; import { Option as OP, pipe } from 'effect'; import { composeMap } from '../../../compose.js'; const liftGiven = () => ( /** * Type of composition requested: `Of`, `Invariant`, `Covariant`, * `Applicative`, `Traversable`, or `Foldable`. */ key, /** * Suffix test label to indicate this is a composition test. */ suffix, /** * Original options for testing the datatype known by the type lambda `F`, * encoding the _inner_ type of the composition. */ { F, getEquivalence, getArbitrary, ...given }) => ({ G, getEquivalenceG, getArbitraryG }) => { const composedGiven = { ...given, F: composeMap[key](G, F), getEquivalence: (equalA) => getEquivalenceG(getEquivalence(equalA)), getArbitrary: (a) => getArbitraryG(getArbitrary(a)), }; return [`${key}Composition.${suffix}`, composedGiven]; }; /** * Return the given options transformed into options for a composed * typeclass test, where the outer composed datatype is an `Option`. * * For example if we are testing `Covariant` laws on `MyTuple`, and * the underlying types are all `number`, then the correct `given` * type required for these tests, is * `ParameterizedGiven<CovariantTypeLambda, MyTupleLambda, number>`. * * If we wanted to run the same law test but on a _composed instance_ * of `MyTuple` inside an `Option`, then we could use this function * to convert the options to the required type. Then we can run these * new options to test typeclass laws on the composed instance. * @returns Typeclass test options for the `F` datatype when it is * wrapped in an `Option`. * @category composition */ export const withOuterOption = ( /** * Type of composition requested: `Of`, `Invariant`, `Covariant`, * `Applicative`, or `Traversable`. The `Option` datatype can do * all of them. */ key, /** * The original {@link ParameterizedGiven} for the typeclass under test as * it is _before_ composition. * */ given, /** * The instance of `Option` for the typeclass under test. */ optionInstance) => pipe({ G: optionInstance, getEquivalenceG: OP.getEquivalence, getArbitraryG: option, }, liftGiven()(key, 'Option<F>', given)); //# sourceMappingURL=compose.js.map