UNPKG

effect-ts-laws

Version:
14 lines 873 B
import { Law, LawSet } from '#law'; import { flow, pipe } from 'effect'; import { covariantLaws } from './Covariant.js'; import { flatMapLaws } from './FlatMap.js'; import { unfoldGiven } from './given.js'; /** * Typeclass laws for `Monad`. * @category typeclass laws */ export const monadLaws = (given, suffix) => { const { a, F, fa, equalsFa, equalsFb, ab, afb } = unfoldGiven(given); return LawSet(covariantLaws(given), flatMapLaws(given))(`Monad${suffix ?? ''}`, Law('left identity', 'of ∘ flatMap(afb) = afb', a, afb)((a, afb) => equalsFb(pipe(a, F.of, F.flatMap(afb)), afb(a))), Law('right identity', 'flatMap(of) = id', fa)(fa => equalsFa(pipe(fa, F.flatMap(F.of)), fa)), Law('map consistency', 'map(ab) = flatMap(of ∘ ab)', fa, ab)((fa, ab) => equalsFb(pipe(fa, F.map(ab)), pipe(fa, F.flatMap(flow(ab, F.of)))))); }; //# sourceMappingURL=Monad.js.map