import { map_ } from "./functor"; import type { Async } from "./model"; import { chain_ } from "./monad"; /* * ------------------------------------------- * Sequential Apply Async * ------------------------------------------- */ export const mapBoth_ = ( fa: Async, fb: Async, f: (a: A, b: B) => C ): Async => chain_(fa, (a) => map_(fb, (b) => f(a, b))); export const mapBoth = (fb: Async, f: (a: A, b: B) => C) => ( fa: Async ): Async => mapBoth_(fa, fb, f); export const ap_ = ( fab: Async B>, fa: Async ): Async => mapBoth_(fab, fa, (f, a) => f(a)); export const ap = (fa: Async) => ( fab: Async B> ): Async => ap_(fab, fa); export const apFirst_ = (fa: Async, fb: Async): Async => mapBoth_(fa, fb, (a, _) => a); export const apFirst = (fb: Async) => (fa: Async): Async => apFirst_(fa, fb); export const apSecond_ = (fa: Async, fb: Async): Async => mapBoth_(fa, fb, (_, b) => b); export const apSecond = (fb: Async) => ( fa: Async ): Async => apSecond_(fa, fb);