UNPKG

effect-ts-folds

Version:
15 lines 1.12 kB
import { fix, unfix } from '#fix'; import { Either as EI, flow, pipe } from 'effect'; import { Law, LawSet } from 'effect-ts-laws'; import { hylo } from '../refold.js'; import { ana, apo } from './schemes.js'; export const anaLaws = (F, { a, equalsF, fixed, ψ }) => { const anaF = ana(F); return LawSet()('anamorphism', Law('identity', 'ana(unfix) = id', fixed)(fixed => equalsF(pipe(fixed, anaF(unfix)), fixed)), Law('hylo consistency', 'ana(ψ) = hylo(ψ, fix)', a, ψ)((a, ψ) => equalsF(pipe(a, anaF(ψ)), pipe(a, hylo(F)(ψ, fix)))), Law('standalone ana consistency', 'ana(ψ) = standaloneAna(ψ)', a, ψ)((a, ψ) => equalsF(pipe(a, anaF(ψ)), pipe(a, standaloneAna(F, ψ))))); }; export const apoLaws = (F, { a, equalsF, ψ }) => { return LawSet()('apomorphism', Law('ana consistency', 'ana(ψ) = apo(F.map(Either.right) ∘ ψ) ', a, ψ)((a, ψ) => equalsF(pipe(a, ana(F)(ψ)), pipe(a, apoBasedAna(F, ψ))))); }; const standaloneAna = (F, ψ) => a => pipe(a, ψ, F.map(standaloneAna(F, ψ)), fix); export const apoBasedAna = (F, ψ) => apo(F)(flow(ψ, F.map(EI.right))); //# sourceMappingURL=laws.js.map