import { bind_, bindTo_, flow, pipe } from "../../Function"; import { succeed } from "./constructors"; import { map, map_ } from "./functor"; import type { Managed } from "./model"; import { chain } from "./monad"; const of = succeed({}); export { of as do }; export const bindS = ( name: Exclude, f: (_: K) => Managed ): (( mk: Managed ) => Managed< R & R2, E | E2, { [k in N | keyof K]: k extends keyof K ? K[k] : A; } >) => chain((a) => pipe( f(a), map((b) => bind_(a, name, b)) ) ); export const bindTo = (name: Exclude) => ( fa: Managed ): Managed]: A }> => map_(fa, bindTo_(name)); export const letS = (name: Exclude, f: (_: K) => A) => bindS(name, flow(f, succeed));