import { identity } from "../Function"; import { succeed } from "./constructors"; import type { Async } from "./model"; import { AsksInstruction, GiveInstruction } from "./model"; /* * ------------------------------------------- * Reader Async * ------------------------------------------- */ export const asksM = (f: (_: R0) => Async): Async => new AsksInstruction(f); export const asks = (f: (_: R) => A): Async => asksM((_: R) => succeed(f(_))); export const ask = (): Async => asks(identity); export const giveAll_ = (ra: Async, env: R): Async => new GiveInstruction(ra, env); export const giveAll = (env: R) => (ra: Async): Async => new GiveInstruction(ra, env); export const local_ = (ra: Async, f: (_: R0) => R): Async => asksM((_: R0) => giveAll_(ra, f(_))); export const local = (f: (_: R0) => R) => (ra: Async): Async => local_(ra, f); export const give_ = (ra: Async, env: R): Async => local_(ra, (r0) => ({ ...env, ...r0 })); export const give = (env: R) => (ra: Async): Async => give_(ra, env);