effect-ts-laws
Version:
effect-ts law testing using fast-check.
55 lines • 1.86 kB
JavaScript
/**
* Arbitraries for various kinds of functions.
* @module
*/
import { pipe } from 'effect';
import fc from 'fast-check';
// flipped “apply”
const applyF = (f) => (a) => f(a);
/**
* Calls
* [fc.function](https://fast-check.dev/docs/core-blocks/arbitraries/composites/function/#func)
* but keeps only the first argument making it act as a function of a single
* argument.
* @category arbitraries
*/
export const unary = () => b => fc.func(b).map(applyF);
/**
* An arbitrary function from `A` to `A`.
* @category arbitraries
*/
export const endo = (a) => fc.func(a).map(applyF);
/**
* Build an arbitrary binary function of type `(a: A, b: B) => C` from an
* arbitrary of `C`.
* @category arbitraries
*/
export const binary = () => (c) => fc.func(c).map(f => (a, b) => f(a, b));
/**
* An arbitrary for a function from `A` to `F<B>`. Requires an
* arbitrary of `B`, a function converting arbitraries of `A` to
* arbitraries of `F<A>`, and the _type_ `A`.
* @returns An arbitrary of type `(a: A) => F<B>`.
* @category arbitraries
*/
export const unaryToKind = () => (getArbitrary) => b => pipe(b, getArbitrary, fc.func).map(applyF);
/**
* An arbitrary for a function from `F<A>` to `B`. Requires an
* arbitrary of `B` and specifying the kind type parameters.
* @returns An arbitrary of type `(a: F<A>) => B`.
* @category arbitraries
*/
export const unaryFromKind = () => b => fc.func(b).map(applyF);
/**
* An arbitrary for the type `F<A⇒B>`. Requires an arbitrary of `B`, a
* function lifting `A` to `F<A>`, and the _type_ `A`.
* @returns An arbitrary of type `F<(a: A) => B>`.
* @category arbitraries
*/
export const unaryInKind = () => (of) => b => unary()(b).map(of);
/**
* An arbitrary predicate of `A`.
* @category arbitraries
*/
export const predicate = () => unary()(fc.boolean());
//# sourceMappingURL=function.js.map