Function liftGiven

Convert the LawSet options of a typeclass test into the options of a composed typeclass test.

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.

const given: ParameterizedGiven< // Original options.
CovariantTypeLambda,
MyTupleLambda,
number
> = …
const composedGiven = liftGiven<
CovariantTypeLambda,
MyTupleLambda, // Wrapped data type.
OptionTypeLambda // Wrapper data type.
>()(
'Covariant', // Name of composed typeclass.
'Option<F>' // Will be used as test label suffix.
options, // The original options.
)(
optionCovariant, // covariant instance for wrapper.
OP.getEquivalence, // LiftEquivalence for wrapper.
option, // LiftArbitrary for wrapper.
)
// Only the datatype type lambda is different between the
// input and output given:
// composedGiven: ParameterizedGiven<
// CovariantTypeLambda, // Still testing same laws.
// ComposeTypeLambda<OptionTypeLambda, MyTupleLambda>,
// number, // Underlying type does not change.
// >
  • Type Parameters

    • Class extends TypeLambda

      Type lambda for the typeclass under test.

    • F extends TypeLambda

      Type lambda for _inner datatype.

    • G extends TypeLambda

      Type lambda for _outer datatype.

    Returns (<K, Os>(key: K, suffix: string, __namedParameters: Os) => ((__namedParameters: FromGiven<Class, F, G, Os>) => readonly [`${K}Composition.${string}`, ComposeGiven<Class, F, G, Os>["given"]]))

      • <K, Os>(key, suffix, __namedParameters): ((__namedParameters: FromGiven<Class, F, G, Os>) => readonly [`${K}Composition.${string}`, ComposeGiven<Class, F, G, Os>["given"]])
      • Type Parameters

        • K extends
              | "Of"
              | "Invariant"
              | "Covariant"
              | "Applicative"
              | "Traversable"
        • Os extends ParameterizedGiven<Class, F, any, any, any, any, any, any>

        Parameters

        • key: K

          Type of composition requested: Of, Invariant, Covariant, Applicative, or Traversable.

        • suffix: string

          Suffix test label to indicate this is a composition test.

        • __namedParameters: Os

          Original options for testing the datatype known by the type lambda F, encoding the inner type of the composition.

        Returns ((__namedParameters: FromGiven<Class, F, G, Os>) => readonly [`${K}Composition.${string}`, ComposeGiven<Class, F, G, Os>["given"]])