effect-ts-laws
Version:
effect-ts law testing using fast-check.
74 lines • 2.57 kB
JavaScript
import { Foldable as FO, } from '@effect/typeclass';
import { mapComposition } from '@effect/typeclass/Covariant';
import { imapComposition } from '@effect/typeclass/Invariant';
import { ofComposition } from '@effect/typeclass/Of';
import { productComposition, productManyComposition, } from '@effect/typeclass/SemiProduct';
import { traverseComposition } from '@effect/typeclass/Traversable';
import { dual, pipe } from 'effect/Function';
/**
* Compose an `Of` instance by nesting a pair of `Of` instances, the
* first on the outside and the second on the inside.
* @category composition
*/
export const composeOf = (F, G) => ({
of: ofComposition(F, G),
});
/**
* Compose an `Invariant` instance by nesting a pair of `Invariants`s, the
* first on the outside and the second on the inside.
* @category composition
*/
export const composeInvariant = (F, G) => ({
imap: dual(3, imapComposition(F, G)),
});
/**
* Compose a `Covariant` instance by nesting a pair of `Covariant`s, the first
* on the outside and the second on the inside.
* @category composition
*/
export const composeCovariant = (F, G) => ({
...composeInvariant(F, G),
map: dual(2, mapComposition(F, G)),
});
/**
* Compose a pair of applicatives. Their composition is an applicative of their
* nested types. Useful when testing traversable composition laws.
* @category composition
*/
export const composeApplicative = (F, G) => ({
...composeCovariant(F, G),
...composeOf(F, G),
product: productComposition(F, G),
productMany: productManyComposition(F, G),
productAll: collection => pipe(collection, F.productAll, F.map(G.productAll)),
});
/**
* Compose a pair of traversables. Their composition is a traversable of their
* nested types.
* @category composition
*/
export const composeTraversable = (F, G) => ({
traverse: (P) => dual(2, traverseComposition(F, G)(P)),
});
/**
* Compose a pair of foldables. Their composition is a foldable of their
* nested types.
* @category composition
*/
export const composeFoldable = (F, G) => ({
reduce: dual(3, (self, b, f) => FO.reduceComposition(F, G)(self, b, f)),
});
/**
* Map of typeclass name to the function that can compose a pair of the
* typeclass instances to create a new instance of the typeclass.
* @category composition
*/
export const composeMap = {
Of: composeOf,
Invariant: composeInvariant,
Covariant: composeCovariant,
Applicative: composeApplicative,
Foldable: composeFoldable,
Traversable: composeTraversable,
};
//# sourceMappingURL=compose.js.map