effect-ts-laws
Version:
effect-ts law testing using fast-check.
52 lines • 2.1 kB
TypeScript
import { LawSet } from '#law';
import { Isomorphism } from '#typeclass';
import { type Equivalence } from 'effect/Equivalence';
import fc from 'fast-check';
/**
* Build typeclass laws for isomorphisms that share their `A` type parameter.
* @category typeclass laws
*/
export declare const buildIsomorphismLaws: <A>(base: BaseIsomorphismGiven<A>) => <Encodings extends BaseEncoding<A>>(encodings: Encodings) => LawSet[];
/**
* Build typeclass laws for `Isomorphism`.
* @category typeclass laws
*/
export declare const isomorphismLaws: <A, B>(suffix: string, { a, b, equalsA, equalsB, F }: IsomorphismGiven<A, B>) => LawSet;
declare module './given.js' {
interface ConcreteLambdas {
Isomorphism: Isomorphism.IsomorphismTypeLambda;
}
}
export type IsomorphismGiven<A, B> = IsomorphismGivenFor<A, B> & BaseIsomorphismGiven<A>;
/**
* Record of arguments required to test several encodings of the type `A`. Each
* `Isomorphism` requires an equivalence and an arbitrary for the encoded type,
* where the key is the encoding name. As all the encodings share a decoded
* type, only a single arbitrary/equivalence of `A` is required.
* @category typeclass laws
*/
export type BaseEncoding<A> = Record<string, IsomorphismGivenFor<A, any>>;
/**
* Arguments required to test a single `Isomorphism<A,B>`.
* @category typeclass laws
*/
export interface IsomorphismGivenFor<A, B> {
/** An equivalence for the decoded values of the isomorphism. */
equalsB: Equivalence<B>;
/** An arbitrary for the decoded values of the isomorphism. */
b: fc.Arbitrary<B>;
/** Instance of the typeclass under test. */
F: Isomorphism.Isomorphism<A, B>;
}
/**
* Shared arguments required for testing an `Isomorphism` with a decoded type
* `A`.
* @category typeclass laws
*/
export interface BaseIsomorphismGiven<A> {
/** An equivalence for the decoded value of the `Isomorphism` of type `A`. */
equalsA: Equivalence<A>;
/** An arbitrary for the decoded value of the `Isomorphism` of type `A`. */
a: fc.Arbitrary<A>;
}
//# sourceMappingURL=Isomorphism.d.ts.map