All files / src/laws/typeclass/monomorphic given.ts

100% Statements 17/17
100% Branches 1/1
100% Functions 1/1
100% Lines 17/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77  1x   1x                                                                                                         1x           40x 40x 40x 40x 40x 40x 40x 40x 40x 40x 40x 40x 40x 40x  
import type {LiftArbitrary} from '#arbitrary'
import {predicate} from '#arbitrary'
import type {LiftEquivalence} from '#law'
import {monoRecord} from '#util'
import {Monoid as MO} from '@effect/typeclass'
import {Equivalence as EQ} from 'effect'
import type {TypeLambda} from 'effect/HKT'
import fc from 'fast-check'
import type {GivenConcerns} from '../parameterized/given.js'
 
/**
 * Options for the monomorphic typeclass test runner.
 * @category monomorphic
 */
export interface MonomorphicGiven<
  F extends TypeLambda,
  R = never,
  O = unknown,
  E = unknown,
> {
  /**
   * A function that will lift arbitraries from any underlying type
   * to arbitraries of `F<A>`.
   */
  getArbitrary: LiftArbitrary<F, R, O, E>
  /**
   * A function that will lift an equivalence for any underlying type
   * info an equivalence of `F<A>`.
   */
  getEquivalence: LiftEquivalence<F, R, O, E>
}
 
/**
 * Options for the monomorphic typeclass test runner on the underlying type `A`.
 * @category monomorphic
 */
export interface MonomorphicGivenOf<
  F extends TypeLambda,
  A,
  R = never,
  O = unknown,
  E = unknown,
> extends MonomorphicGiven<F, R, O, E> {
  /** An arbitrary for the underlying type `A`. */
  a: fc.Arbitrary<A>
  /** An equivalence for the underlying type `A`. */
  equalsA: EQ.Equivalence<A>
  /** A monoid for the underlying type `A`. */
  Monoid: MO.Monoid<A>
}
 
/**
 * Build the options for monomorphic typeclass law tests on the underlying type
 * `A`.
 * @category monomorphic
 */
export const unfoldMonomorphicGiven = <
  F extends TypeLambda,
  A,
  R = never,
  O = unknown,
  E = unknown,
>({
  a,
  equalsA,
  getEquivalence,
  getArbitrary,
  Monoid,
}: MonomorphicGivenOf<F, A, R, O, E>): GivenConcerns<F, A, A, A, R, O, E> => ({
  ...monoRecord(a)('a', 'b', 'c'),
  ...monoRecord(equalsA)('equalsA', 'equalsB', 'equalsC'),
  ...monoRecord(predicate<A>())('predicateA', 'predicateB', 'predicateC'),
  getArbitrary,
  getEquivalence,
  Monoid,
})