import { identity } from "../Function"; import { ChainInstruction } from "./model"; import { map_ } from "./functor"; import type { XPure } from "./model"; /* * ------------------------------------------- * Monad XPure * ------------------------------------------- */ export const chain_ = ( ma: XPure, f: (a: A) => XPure ): XPure => new ChainInstruction(ma, f); export const chain = (f: (a: A) => XPure) => ( ma: XPure ): XPure => chain_(ma, f); export const tap_ = ( ma: XPure, f: (a: A) => XPure ): XPure => chain_(ma, (a) => map_(f(a), () => a)); export const tap = (f: (a: A) => XPure) => ( ma: XPure ): XPure => tap_(ma, f); export const flatten = ( mma: XPure> ): XPure => chain_(mma, identity);