import {
  do_3 as do_
} from "./chunk-3AL4EMTU.mjs";
import {
  getApplicativeMonoid
} from "./chunk-LN4UQKIO.mjs";
import {
  as,
  asUnit,
  bindTo,
  flap,
  let_
} from "./chunk-WKK6AYQI.mjs";
import {
  apFirst,
  apS,
  apSecond,
  getApplySemigroup
} from "./chunk-ZMCLCMOU.mjs";
import {
  bind,
  tap
} from "./chunk-MDNVYLGG.mjs";
import {
  emptyReadonlyArray,
  emptyRecord,
  head,
  isNonEmpty
} from "./chunk-WPJQNT3M.mjs";
import {
  constant,
  dual,
  identity
} from "./chunk-ZI34HWXZ.mjs";
import {
  __export
} from "./chunk-QK4PKNB3.mjs";

// src/IO.ts
var IO_exports = {};
__export(IO_exports, {
  ApT: () => ApT,
  Applicative: () => Applicative,
  Apply: () => Apply,
  Chain: () => Chain,
  ChainRec: () => ChainRec,
  Do: () => Do,
  FromIO: () => FromIO,
  Functor: () => Functor,
  Monad: () => Monad,
  MonadIO: () => MonadIO,
  Pointed: () => Pointed,
  URI: () => URI,
  ap: () => ap,
  apFirst: () => apFirst2,
  apS: () => apS2,
  apSecond: () => apSecond2,
  as: () => as2,
  asUnit: () => asUnit2,
  bind: () => bind2,
  bindTo: () => bindTo2,
  chain: () => chain,
  chainFirst: () => chainFirst,
  chainRec: () => chainRec,
  do: () => do_2,
  flap: () => flap2,
  flatMap: () => flatMap,
  flatten: () => flatten,
  fromIO: () => fromIO,
  getMonoid: () => getMonoid,
  getSemigroup: () => getSemigroup,
  io: () => io,
  let: () => let_2,
  map: () => map,
  of: () => of,
  sequenceArray: () => sequenceArray,
  tap: () => tap2,
  traverseArray: () => traverseArray,
  traverseArrayWithIndex: () => traverseArrayWithIndex,
  traverseReadonlyArrayWithIndex: () => traverseReadonlyArrayWithIndex,
  traverseReadonlyNonEmptyArrayWithIndex: () => traverseReadonlyNonEmptyArrayWithIndex
});
var _map = (ma, f) => () => f(ma());
var _ap = (mab, ma) => () => mab()(ma());
var map = (f) => (fa) => _map(fa, f);
var ap = (fa) => (fab) => _ap(fab, fa);
var of = constant;
var flatMap = /* @__PURE__ */ dual(
  2,
  (ma, f) => () => f(ma())()
);
var flatten = /* @__PURE__ */ flatMap(identity);
var URI = "IO";
var Functor = {
  URI,
  map: _map
};
var as2 = dual(2, as(Functor));
var asUnit2 = asUnit(Functor);
var flap2 = /* @__PURE__ */ flap(Functor);
var Pointed = {
  URI,
  of
};
var Apply = {
  URI,
  map: _map,
  ap: _ap
};
var apFirst2 = /* @__PURE__ */ apFirst(Apply);
var apSecond2 = /* @__PURE__ */ apSecond(Apply);
var Applicative = {
  URI,
  map: _map,
  ap: _ap,
  of
};
var Chain = {
  URI,
  map: _map,
  ap: _ap,
  chain: flatMap
};
var Monad = {
  URI,
  map: _map,
  ap: _ap,
  of,
  chain: flatMap
};
var tap2 = /* @__PURE__ */ dual(2, tap(Chain));
var fromIO = identity;
var MonadIO = {
  URI,
  map: _map,
  ap: _ap,
  of,
  chain: flatMap,
  fromIO
};
var chainRec = (a, f) => () => {
  let e = f(a)();
  while (e._tag === "Left") {
    e = f(e.left)();
  }
  return e.right;
};
var ChainRec = {
  URI,
  map: _map,
  ap: _ap,
  chain: flatMap,
  chainRec
};
var FromIO = {
  URI,
  fromIO: identity
};
var Do = /* @__PURE__ */ of(emptyRecord);
var bindTo2 = /* @__PURE__ */ bindTo(Functor);
var let_2 = /* @__PURE__ */ let_(Functor);
var bind2 = /* @__PURE__ */ bind(Chain);
var apS2 = /* @__PURE__ */ apS(Apply);
var ApT = /* @__PURE__ */ of(emptyReadonlyArray);
var do_2 = do_(Pointed, ChainRec);
var traverseReadonlyNonEmptyArrayWithIndex = (f) => (as3) => () => {
  const out = [f(0, head(as3))()];
  for (let i = 1; i < as3.length; i++) {
    out.push(f(i, as3[i])());
  }
  return out;
};
var traverseReadonlyArrayWithIndex = (f) => {
  const g = traverseReadonlyNonEmptyArrayWithIndex(f);
  return (as3) => isNonEmpty(as3) ? g(as3) : ApT;
};
var traverseArrayWithIndex = traverseReadonlyArrayWithIndex;
var traverseArray = (f) => traverseReadonlyArrayWithIndex((_, a) => f(a));
var sequenceArray = /* @__PURE__ */ traverseArray(identity);
var chain = flatMap;
var chainFirst = tap2;
var io = {
  URI,
  map: _map,
  of,
  ap: _ap,
  chain: flatMap,
  fromIO,
  chainRec
};
var getSemigroup = /* @__PURE__ */ getApplySemigroup(Apply);
var getMonoid = /* @__PURE__ */ getApplicativeMonoid(Applicative);

export {
  map,
  ap,
  of,
  flatMap,
  flatten,
  URI,
  Functor,
  as2 as as,
  asUnit2 as asUnit,
  flap2 as flap,
  Pointed,
  Apply,
  apFirst2 as apFirst,
  apSecond2 as apSecond,
  Applicative,
  Chain,
  Monad,
  tap2 as tap,
  fromIO,
  MonadIO,
  chainRec,
  ChainRec,
  FromIO,
  Do,
  bindTo2 as bindTo,
  let_2 as let_,
  bind2 as bind,
  apS2 as apS,
  ApT,
  do_2 as do_,
  traverseReadonlyNonEmptyArrayWithIndex,
  traverseReadonlyArrayWithIndex,
  traverseArrayWithIndex,
  traverseArray,
  sequenceArray,
  chain,
  chainFirst,
  io,
  getSemigroup,
  getMonoid,
  IO_exports
};
