import { pipe } from "../../Function"; import type { Cause } from "../Exit/Cause"; import * as T from "./_internal/task"; import { Managed } from "./model"; /* * ------------------------------------------- * Fold Managed * ------------------------------------------- */ /** * A more powerful version of `foldM` that allows recovering from any kind of failure except interruptions. */ export const foldCauseM = ( f: (cause: Cause) => Managed, g: (a: A) => Managed ) => (self: Managed) => foldCauseM_(self, f, g); /** * A more powerful version of `foldM` that allows recovering from any kind of failure except interruptions. */ export const foldCauseM_ = ( self: Managed, f: (cause: Cause) => Managed, g: (a: A) => Managed ) => new Managed( pipe( self.task, T.foldCauseM( (c) => f(c).task, ([_, a]) => g(a).task ) ) );