import {
  snd
} from "./chunk-R5LTAZ6X.mjs";
import {
  pipe
} from "./chunk-ZI34HWXZ.mjs";
import {
  __export
} from "./chunk-QK4PKNB3.mjs";

// src/StateT.ts
var StateT_exports = {};
__export(StateT_exports, {
  ap: () => ap,
  chain: () => chain,
  evaluate: () => evaluate,
  execute: () => execute,
  flatMap: () => flatMap,
  fromF: () => fromF,
  fromState: () => fromState,
  getStateM: () => getStateM,
  map: () => map,
  of: () => of
});
function of(F) {
  return (a) => (s) => F.of([a, s]);
}
function map(F) {
  return (f) => (fa) => (s) => F.map(fa(s), ([a, s1]) => [f(a), s1]);
}
function ap(M) {
  return (fa) => (fab) => (s) => M.chain(fab(s), ([f, s2]) => M.map(fa(s2), ([a, s3]) => [f(a), s3]));
}
function chain(M) {
  const flatMapM = flatMap(M);
  return (f) => (ma) => flatMapM(ma, f);
}
function flatMap(M) {
  return (ma, f) => (s) => M.chain(ma(s), ([a, s1]) => f(a)(s1));
}
function fromState(F) {
  return (sa) => (s) => F.of(sa(s));
}
function fromF(F) {
  return (ma) => (s) => F.map(ma, (a) => [a, s]);
}
function evaluate(F) {
  return (s) => (ma) => F.map(ma(s), ([a]) => a);
}
function execute(F) {
  return (s) => (ma) => F.map(ma(s), snd);
}
function getStateM(M) {
  const _ap = ap(M);
  const _map = map(M);
  const _chain = chain(M);
  const _evaluate = evaluate(M);
  const _execute = execute(M);
  return {
    map: (fa, f) => pipe(fa, _map(f)),
    ap: (fab, fa) => pipe(fab, _ap(fa)),
    of: of(M),
    chain: (ma, f) => pipe(ma, _chain(f)),
    get: () => (s) => M.of([s, s]),
    put: (s) => () => M.of([void 0, s]),
    modify: (f) => (s) => M.of([void 0, f(s)]),
    gets: (f) => (s) => M.of([f(s), s]),
    fromState: fromState(M),
    fromM: fromF(M),
    evalState: (fa, s) => pipe(fa, _evaluate(s)),
    execState: (fa, s) => pipe(fa, _execute(s))
  };
}

export {
  of,
  map,
  ap,
  chain,
  flatMap,
  fromState,
  fromF,
  evaluate,
  execute,
  getStateM,
  StateT_exports
};
