effect-ts-folds
Version:
Recursion schemes for effect-ts.
18 lines • 810 B
JavaScript
import { fanout } from '#util';
import { Array as AR, pipe } from 'effect';
/**
* Convert a tuple of algebras into an algebra of a tuple.
* @category ops
*/
export const zipFolds = (F) => (...[head, ...tail]) => pipe(tail, AR.reduce(unaryTuple(F)(head), (previous, current) => appendFold(F)(previous, current)));
/**
* Append an algebra to an algebra of a tuple.
* @category ops
*/
export const appendFold = (F) => (algebra, append) => f => pipe(f, fanout(F.map(xs => AR.initNonEmpty(xs)), F.map(xs => AR.lastNonEmpty(xs))), ([algebraArg, appendArg]) => [...algebra(algebraArg), append(appendArg)]);
/**
* Convert an algebra of `A` into an algebra of `[A]`.
* @category ops
*/
export const unaryTuple = (F) => (fold) => fa => [pipe(fa, F.map(AR.headNonEmpty), fold)];
//# sourceMappingURL=tuple.js.map