import { succeed } from "./constructors"; import { foldM_ } from "./fold"; import type { XPure } from "./model"; /* * ------------------------------------------- * Bifunctor XPure * ------------------------------------------- */ export const bimap_ = ( pab: XPure, f: (e: E) => G, g: (a: A) => B ): XPure => foldM_( pab, (e) => fail(f(e)), (a) => succeed(g(a)) ); export const bimap = (f: (e: E) => G, g: (a: A) => B) => ( pab: XPure ): XPure => bimap_(pab, f, g); export const first_ = (pab: XPure, f: (e: E) => G): XPure => foldM_(pab, (e) => fail(f(e)), succeed); export const first = (f: (e: E) => G) => (pab: XPure): XPure => first_(pab, f);