import { flow } from "../Function"; import { succeed } from "./constructors"; import type { Async } from "./model"; import { FoldInstruction } from "./model"; /* * ------------------------------------------- * Async Folds * ------------------------------------------- */ export const foldM_ = ( async: Async, f: (e: E) => Async, g: (a: A) => Async ): Async => new FoldInstruction(async, f, g); export const foldM = (f: (e: E) => Async, g: (a: A) => Async) => < R >( async: Async ): Async => foldM_(async, f, g); export const fold_ = (async: Async, f: (e: E) => B, g: (a: A) => C): Async => foldM_(async, flow(f, succeed), flow(g, succeed)); export const fold = (f: (e: E) => B, g: (a: A) => C) => ( async: Async ): Async => fold_(async, f, g); export const catchAll_ = ( async: Async, f: (e: E) => Async ): Async => foldM_(async, f, succeed); export const catchAll = (f: (e: E) => Async) => ( async: Async ): Async => catchAll_(async, f);