"use strict";Object.defineProperty(exports, "__esModule", {value: true});

var _chunkS2Z5L3RBjs = require('./chunk-S2Z5L3RB.js');




var _chunk7K74W2G3js = require('./chunk-7K74W2G3.js');




var _chunkQ2LZCTWPjs = require('./chunk-Q2LZCTWP.js');



var _chunkEBISTSVAjs = require('./chunk-EBISTSVA.js');





var _chunkOTKMOSH2js = require('./chunk-OTKMOSH2.js');




var _chunkSQA7G4TEjs = require('./chunk-SQA7G4TE.js');


var _chunk6C3VEZWHjs = require('./chunk-6C3VEZWH.js');

// src/State.ts
var State_exports = {};
_chunk6C3VEZWHjs.__export.call(void 0, State_exports, {
  Applicative: () => Applicative,
  Apply: () => Apply,
  Chain: () => Chain,
  ChainRec: () => ChainRec,
  FromState: () => FromState,
  Functor: () => Functor,
  Monad: () => Monad,
  Pointed: () => Pointed,
  URI: () => URI,
  ap: () => ap,
  apFirst: () => apFirst2,
  apS: () => apS2,
  apSecond: () => apSecond2,
  bind: () => bind2,
  bindTo: () => bindTo2,
  chain: () => chain,
  chainFirst: () => chainFirst,
  chainRec: () => chainRec,
  do: () => do_2,
  evalState: () => evalState,
  evaluate: () => evaluate,
  execState: () => execState,
  execute: () => execute,
  flap: () => flap2,
  flatMap: () => flatMap,
  flatten: () => flatten,
  get: () => get,
  gets: () => gets,
  let: () => let_2,
  map: () => map,
  modify: () => modify,
  of: () => of,
  put: () => put,
  sequenceArray: () => sequenceArray,
  state: () => state,
  tap: () => tap2,
  traverseArray: () => traverseArray,
  traverseArrayWithIndex: () => traverseArrayWithIndex,
  traverseReadonlyArrayWithIndex: () => traverseReadonlyArrayWithIndex,
  traverseReadonlyNonEmptyArrayWithIndex: () => traverseReadonlyNonEmptyArrayWithIndex
});
var get = () => (s) => [s, s];
var put = (s) => () => [void 0, s];
var modify = (f) => (s) => [void 0, f(s)];
var gets = (f) => (s) => [f(s), s];
var _map = (fa, f) => _chunkSQA7G4TEjs.pipe.call(void 0, fa, map(f));
var _ap = (fab, fa) => _chunkSQA7G4TEjs.pipe.call(void 0, fab, ap(fa));
var map = (f) => (fa) => (s1) => {
  const [a, s2] = fa(s1);
  return [f(a), s2];
};
var ap = (fa) => (fab) => (s1) => {
  const [f, s2] = fab(s1);
  const [a, s3] = fa(s2);
  return [f(a), s3];
};
var of = (a) => (s) => [a, s];
var flatMap = /* @__PURE__ */ _chunkSQA7G4TEjs.dual.call(void 0, 
  2,
  (ma, f) => (s1) => {
    const [a, s2] = ma(s1);
    return f(a)(s2);
  }
);
var flatten = /* @__PURE__ */ flatMap(_chunkSQA7G4TEjs.identity);
var URI = "State";
var Functor = {
  URI,
  map: _map
};
var flap2 = /* @__PURE__ */ _chunk7K74W2G3js.flap.call(void 0, Functor);
var Pointed = {
  URI,
  of
};
var Apply = {
  URI,
  map: _map,
  ap: _ap
};
var apFirst2 = /* @__PURE__ */ _chunkQ2LZCTWPjs.apFirst.call(void 0, Apply);
var apSecond2 = /* @__PURE__ */ _chunkQ2LZCTWPjs.apSecond.call(void 0, Apply);
var Applicative = {
  URI,
  map: _map,
  ap: _ap,
  of
};
var Chain = {
  URI,
  map: _map,
  ap: _ap,
  chain: flatMap
};
var chainRec = (a, f) => (initialState) => {
  let [current, state2] = f(a)(initialState);
  while (_chunkOTKMOSH2js.isLeft.call(void 0, current)) {
    ;
    [current, state2] = f(current.left)(state2);
  }
  return [current.right, state2];
};
var ChainRec = {
  ...Chain,
  chainRec
};
var Monad = {
  URI,
  map: _map,
  ap: _ap,
  of,
  chain: flatMap
};
var tap2 = /* @__PURE__ */ _chunkSQA7G4TEjs.dual.call(void 0, 2, _chunkEBISTSVAjs.tap.call(void 0, Chain));
var FromState = {
  URI,
  fromState: _chunkSQA7G4TEjs.identity
};
var evaluate = (s) => (ma) => ma(s)[0];
var execute = (s) => (ma) => ma(s)[1];
var bindTo2 = /* @__PURE__ */ _chunk7K74W2G3js.bindTo.call(void 0, Functor);
var let_2 = /* @__PURE__ */ _chunk7K74W2G3js.let_.call(void 0, Functor);
var bind2 = /* @__PURE__ */ _chunkEBISTSVAjs.bind.call(void 0, Chain);
var do_2 = _chunkS2Z5L3RBjs.do_3.call(void 0, Pointed, ChainRec);
var apS2 = /* @__PURE__ */ _chunkQ2LZCTWPjs.apS.call(void 0, Apply);
var traverseReadonlyNonEmptyArrayWithIndex = (f) => (as) => (s) => {
  const [b, s2] = f(0, _chunkOTKMOSH2js.head.call(void 0, as))(s);
  const bs = [b];
  let out = s2;
  for (let i = 1; i < as.length; i++) {
    const [b2, s22] = f(i, as[i])(out);
    bs.push(b2);
    out = s22;
  }
  return [bs, out];
};
var traverseReadonlyArrayWithIndex = (f) => {
  const g = traverseReadonlyNonEmptyArrayWithIndex(f);
  return (as) => _chunkOTKMOSH2js.isNonEmpty.call(void 0, as) ? g(as) : of(_chunkOTKMOSH2js.emptyReadonlyArray);
};
var traverseArrayWithIndex = traverseReadonlyArrayWithIndex;
var traverseArray = (f) => traverseReadonlyArrayWithIndex((_, a) => f(a));
var sequenceArray = /* @__PURE__ */ traverseArray(_chunkSQA7G4TEjs.identity);
var chain = flatMap;
var chainFirst = tap2;
var evalState = (ma, s) => ma(s)[0];
var execState = (ma, s) => ma(s)[1];
var state = Monad;











































exports.get = get; exports.put = put; exports.modify = modify; exports.gets = gets; exports.map = map; exports.ap = ap; exports.of = of; exports.flatMap = flatMap; exports.flatten = flatten; exports.URI = URI; exports.Functor = Functor; exports.flap = flap2; exports.Pointed = Pointed; exports.Apply = Apply; exports.apFirst = apFirst2; exports.apSecond = apSecond2; exports.Applicative = Applicative; exports.Chain = Chain; exports.chainRec = chainRec; exports.ChainRec = ChainRec; exports.Monad = Monad; exports.tap = tap2; exports.FromState = FromState; exports.evaluate = evaluate; exports.execute = execute; exports.bindTo = bindTo2; exports.let_ = let_2; exports.bind = bind2; exports.do_ = do_2; exports.apS = apS2; exports.traverseReadonlyNonEmptyArrayWithIndex = traverseReadonlyNonEmptyArrayWithIndex; exports.traverseReadonlyArrayWithIndex = traverseReadonlyArrayWithIndex; exports.traverseArrayWithIndex = traverseArrayWithIndex; exports.traverseArray = traverseArray; exports.sequenceArray = sequenceArray; exports.chain = chain; exports.chainFirst = chainFirst; exports.evalState = evalState; exports.execState = execState; exports.state = state; exports.State_exports = State_exports;
