import type { Either } from "../../Either"; import * as T from "../Task/_core"; import type { XRefM } from "./model"; /** * Folds over the error and value types of the `XRefM`. */ export const fold_ = ( self: XRefM, ea: (_: EA) => EC, eb: (_: EB) => ED, ca: (_: C) => Either, bd: (_: B) => Either ): XRefM => self.foldM( ea, eb, (c) => T.fromEither(() => ca(c)), (b) => T.fromEither(() => bd(b)) ); /** * Folds over the error and value types of the `XRefM`. */ export const fold = ( ea: (_: EA) => EC, eb: (_: EB) => ED, ca: (_: C) => Either, bd: (_: B) => Either ) => (self: XRefM): XRefM => self.foldM( ea, eb, (c) => T.fromEither(() => ca(c)), (b) => T.fromEither(() => bd(b)) ); /** * Folds over the error and value types of the `XRefM`. This is a highly * polymorphic method that is capable of arbitrarily transforming the error * and value types of the `XRefM`. For most use cases one of the more * specific combinators implemented in terms of `foldM` will be more * ergonomic but this method is extremely useful for implementing new * combinators. */ export const foldM_ = ( self: XRefM, ea: (_: EA) => EC, eb: (_: EB) => ED, ca: (_: C) => T.Task, bd: (_: B) => T.Task ): XRefM => self.foldM(ea, eb, ca, bd); /** * Folds over the error and value types of the `XRefM`. This is a highly * polymorphic method that is capable of arbitrarily transforming the error * and value types of the `XRefM`. For most use cases one of the more * specific combinators implemented in terms of `foldM` will be more * ergonomic but this method is extremely useful for implementing new * combinators. */ export const foldM = ( ea: (_: EA) => EC, eb: (_: EB) => ED, ca: (_: C) => T.Task, bd: (_: B) => T.Task ) => (self: XRefM): XRefM => self.foldM(ea, eb, ca, bd); /** * Folds over the error and value types of the `XRefM`, allowing access to * the state in transforming the `set` value. This is a more powerful version * of `foldM` but requires unifying the environment and error types. */ export const foldAllM_ = ( self: XRefM, ea: (_: EA) => EC, eb: (_: EB) => ED, ec: (_: EB) => EC, ca: (_: C) => (_: B) => T.Task, bd: (_: B) => T.Task ): XRefM => self.foldAllM(ea, eb, ec, ca, bd); /** * Folds over the error and value types of the `XRefM`, allowing access to * the state in transforming the `set` value. This is a more powerful version * of `foldM` but requires unifying the environment and error types. */ export const foldAllM = ( ea: (_: EA) => EC, eb: (_: EB) => ED, ec: (_: EB) => EC, ca: (_: C) => (_: B) => T.Task, bd: (_: B) => T.Task ) => (self: XRefM): XRefM => self.foldAllM(ea, eb, ec, ca, bd);