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