import { right } from "../../Either"; import { pipe } from "../../Function"; import type * as T from "../Task/_core"; import { fold } from "./fold"; import type { XRefM } from "./model"; /** * Transforms both the `set` and `get` values of the `XRefM` with the * specified effectual functions. */ export const bimapM_ = ( self: XRefM, f: (c: C) => T.Task, g: (b: B) => T.Task ) => self.foldM( (ea: EA | EC) => ea, (eb: EB | ED) => eb, f, g ); /** * Transforms both the `set` and `get` values of the `XRefM` with the * specified effectual functions. */ export const bimapM = ( f: (c: C) => T.Task, g: (b: B) => T.Task ) => (self: XRefM) => bimapM_(self, f, g); /** * Transforms both the `set` and `get` errors of the `XRefM` with the * specified functions. */ export const bimapError_ = ( self: XRefM, f: (ea: EA) => EC, g: (eb: EB) => ED ): XRefM => pipe( self, fold( (ea) => f(ea), (eb) => g(eb), (a) => right(a), (b) => right(b) ) ); /** * Transforms both the `set` and `get` errors of the `XRefM` with the * specified functions. */ export const bimapError = (f: (ea: EA) => EC, g: (eb: EB) => ED) => ( self: XRefM ): XRefM => bimapError_(self, f, g);