import type { _A, _E, _R } from "../support/utils"; import { map_ } from "./functor"; import type { Async } from "./model"; import { AllInstruction } from "./model"; /* * ------------------------------------------- * Parallel Apply Async * ------------------------------------------- */ export const sequenceTPar = >>( ...asyncs: A & { 0: Async } ): Async<_R, _E, { [K in keyof A]: _A }> => new AllInstruction(asyncs) as any; export const mapBothPar_ = ( fa: Async, fb: Async, f: (a: A, b: B) => C ): Async => map_(sequenceTPar(fa, fb), ([a, b]) => f(a, b)); export const mapBothPar = (fb: Async, f: (a: A, b: B) => C) => ( fa: Async ): Async => mapBothPar_(fa, fb, f); export const apPar_ = ( fab: Async B>, fa: Async ): Async => mapBothPar_(fab, fa, (f, a) => f(a)); export const apPar = (fa: Async) => ( fab: Async B> ): Async => apPar_(fab, fa); export const apFirstPar_ = (fa: Async, fb: Async): Async => mapBothPar_(fa, fb, (a, _) => a); export const apFirstPar = (fb: Async) => ( fa: Async ): Async => apFirstPar_(fa, fb); export const apSecondPar_ = ( fa: Async, fb: Async ): Async => mapBothPar_(fa, fb, (_, b) => b); export const apSecondPar = (fb: Async) => ( fa: Async ): Async => apSecondPar_(fa, fb);