import type * as P from "@principia/prelude"; import * as HKT from "@principia/prelude/HKT"; import * as X from "../XPure"; import { Functor, map_ } from "./functor"; import type { EIO, URI, V } from "./model"; /* * ------------------------------------------- * Apply EIO * ------------------------------------------- */ export const ap_ = (fab: EIO B>, fa: EIO): EIO => X.map_(X.both_(fab, fa), ([f, a]) => f(a)); export const ap = (fa: EIO) => (fab: EIO B>): EIO => ap_(fab, fa); export const apFirst_ = (fa: EIO, fb: EIO): EIO => ap_( map_(fa, (a) => () => a), fb ); export const apFirst = (fb: EIO) => (fa: EIO): EIO => apFirst_(fa, fb); export const apSecond_ = (fa: EIO, fb: EIO): EIO => ap_( map_(fa, () => (b: B) => b), fb ); export const apSecond = (fb: EIO) => (fa: EIO): EIO => apSecond_(fa, fb); export const mapBoth_: (fa: EIO, fb: EIO, f: (a: A, b: B) => C) => EIO = X.mapBoth_; export const mapBoth: (fb: EIO, f: (a: A, b: B) => C) => (fa: EIO) => EIO = X.mapBoth; export const lift2 = (f: (a: A) => (b: B) => C) => (fa: EIO) => (fb: EIO): EIO => ap_( map_(fa, (a) => (b: B) => f(a)(b)), fb ); /** * @category Apply * @since 1.0.0 */ export const Apply: P.Apply<[URI], V> = HKT.instance({ ...Functor, ap_: ap_, ap, mapBoth_: mapBoth_, mapBoth });