import {
  ask,
  asks,
  fromReaderK,
  tapReader
} from "./chunk-ZUUTK32Y.mjs";
import {
  asksReaderW,
  local,
  map,
  of,
  traverseReadonlyNonEmptyArrayWithIndex
} from "./chunk-AHSGWEN4.mjs";
import {
  ap,
  flatMap,
  fromReader,
  map as map2,
  of as of2
} from "./chunk-T6BWR2PC.mjs";
import {
  fromTaskK,
  tapTask
} from "./chunk-WCFCQNDF.mjs";
import {
  ApplyPar,
  Functor,
  Monad,
  Pointed,
  fromIO,
  traverseReadonlyNonEmptyArrayWithIndex as traverseReadonlyNonEmptyArrayWithIndex2,
  traverseReadonlyNonEmptyArrayWithIndexSeq
} from "./chunk-64PLWQD3.mjs";
import {
  fromIOK,
  tapIO
} from "./chunk-TUMMPMRG.mjs";
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,
  flatMapIO,
  flatMapReader,
  flatMapTask,
  isLeft,
  isNonEmpty
} from "./chunk-WPJQNT3M.mjs";
import {
  SK,
  dual,
  flow,
  identity,
  pipe
} from "./chunk-ZI34HWXZ.mjs";
import {
  __export
} from "./chunk-QK4PKNB3.mjs";

// src/ReaderTask.ts
var ReaderTask_exports = {};
__export(ReaderTask_exports, {
  ApT: () => ApT,
  ApplicativePar: () => ApplicativePar,
  ApplicativeSeq: () => ApplicativeSeq,
  ApplyPar: () => ApplyPar2,
  ApplySeq: () => ApplySeq,
  Chain: () => Chain,
  ChainRec: () => ChainRec,
  Do: () => Do,
  FromIO: () => FromIO,
  FromReader: () => FromReader,
  FromTask: () => FromTask,
  Functor: () => Functor2,
  Monad: () => Monad2,
  MonadIO: () => MonadIO,
  MonadTask: () => MonadTask,
  Pointed: () => Pointed2,
  URI: () => URI,
  ap: () => ap2,
  apFirst: () => apFirst2,
  apS: () => apS2,
  apSW: () => apSW,
  apSecond: () => apSecond2,
  apW: () => apW,
  as: () => as2,
  asUnit: () => asUnit2,
  ask: () => ask2,
  asks: () => asks2,
  asksReaderTask: () => asksReaderTask,
  asksReaderTaskW: () => asksReaderTaskW,
  bind: () => bind2,
  bindTo: () => bindTo2,
  bindW: () => bindW,
  chain: () => chain,
  chainFirst: () => chainFirst,
  chainFirstIOK: () => chainFirstIOK,
  chainFirstReaderIOK: () => chainFirstReaderIOK,
  chainFirstReaderIOKW: () => chainFirstReaderIOKW,
  chainFirstReaderK: () => chainFirstReaderK,
  chainFirstReaderKW: () => chainFirstReaderKW,
  chainFirstTaskK: () => chainFirstTaskK,
  chainFirstW: () => chainFirstW,
  chainIOK: () => chainIOK,
  chainReaderIOK: () => chainReaderIOK,
  chainReaderIOKW: () => chainReaderIOKW,
  chainReaderK: () => chainReaderK,
  chainReaderKW: () => chainReaderKW,
  chainRec: () => chainRec,
  chainTaskK: () => chainTaskK,
  chainW: () => chainW,
  do: () => do_2,
  flap: () => flap2,
  flatMap: () => flatMap2,
  flatMapIO: () => flatMapIO2,
  flatMapReader: () => flatMapReader2,
  flatMapReaderIO: () => flatMapReaderIO,
  flatMapTask: () => flatMapTask2,
  flatten: () => flatten,
  flattenW: () => flattenW,
  fromIO: () => fromIO2,
  fromIOK: () => fromIOK2,
  fromReader: () => fromReader2,
  fromReaderIO: () => fromReaderIO,
  fromReaderIOK: () => fromReaderIOK,
  fromReaderK: () => fromReaderK2,
  fromTask: () => fromTask,
  fromTaskK: () => fromTaskK2,
  getMonoid: () => getMonoid,
  getSemigroup: () => getSemigroup,
  let: () => let_2,
  local: () => local2,
  map: () => map3,
  of: () => of3,
  readerTask: () => readerTask,
  readerTaskSeq: () => readerTaskSeq,
  run: () => run,
  sequenceArray: () => sequenceArray,
  sequenceSeqArray: () => sequenceSeqArray,
  tap: () => tap2,
  tapIO: () => tapIO2,
  tapReader: () => tapReader2,
  tapReaderIO: () => tapReaderIO,
  tapTask: () => tapTask2,
  traverseArray: () => traverseArray,
  traverseArrayWithIndex: () => traverseArrayWithIndex,
  traverseReadonlyArrayWithIndex: () => traverseReadonlyArrayWithIndex,
  traverseReadonlyArrayWithIndexSeq: () => traverseReadonlyArrayWithIndexSeq,
  traverseReadonlyNonEmptyArrayWithIndex: () => traverseReadonlyNonEmptyArrayWithIndex3,
  traverseReadonlyNonEmptyArrayWithIndexSeq: () => traverseReadonlyNonEmptyArrayWithIndexSeq2,
  traverseSeqArray: () => traverseSeqArray,
  traverseSeqArrayWithIndex: () => traverseSeqArrayWithIndex
});
var fromReader2 = /* @__PURE__ */ fromReader(Pointed);
var fromTask = of;
var fromIO2 = /* @__PURE__ */ flow(fromIO, fromTask);
var fromReaderIO = map(fromIO);
var local2 = local;
var asksReaderTaskW = asksReaderW;
var asksReaderTask = asksReaderTaskW;
var _map = (fa, f) => pipe(fa, map3(f));
var _apPar = (fab, fa) => pipe(fab, ap2(fa));
var _apSeq = (fab, fa) => flatMap2(fab, (f) => pipe(fa, map3(f)));
var map3 = /* @__PURE__ */ map2(
  Functor
);
var ap2 = /* @__PURE__ */ ap(ApplyPar);
var apW = ap2;
var of3 = /* @__PURE__ */ of2(Pointed);
var flatMap2 = /* @__PURE__ */ dual(2, flatMap(Monad));
var flattenW = /* @__PURE__ */ flatMap2(identity);
var flatten = flattenW;
var URI = "ReaderTask";
var Functor2 = {
  URI,
  map: _map
};
var as2 = dual(2, as(Functor2));
var asUnit2 = asUnit(Functor2);
var flap2 = /* @__PURE__ */ flap(Functor2);
var Pointed2 = {
  URI,
  of: of3
};
var ApplyPar2 = {
  URI,
  map: _map,
  ap: _apPar
};
var apFirst2 = /* @__PURE__ */ apFirst(ApplyPar2);
var apSecond2 = /* @__PURE__ */ apSecond(ApplyPar2);
var ApplicativePar = {
  URI,
  map: _map,
  ap: _apPar,
  of: of3
};
var ApplySeq = {
  URI,
  map: _map,
  ap: _apSeq
};
var ApplicativeSeq = {
  URI,
  map: _map,
  ap: _apSeq,
  of: of3
};
var Chain = {
  URI,
  map: _map,
  ap: _apPar,
  chain: flatMap2
};
var chainRec = (a, f) => (r) => async () => {
  let current = await f(a)(r)();
  while (isLeft(current)) {
    current = await f(current.left)(r)();
  }
  return current.right;
};
var ChainRec = {
  ...Chain,
  chainRec
};
var Monad2 = {
  URI,
  map: _map,
  of: of3,
  ap: _apPar,
  chain: flatMap2
};
var MonadIO = {
  URI,
  map: _map,
  of: of3,
  ap: _apPar,
  chain: flatMap2,
  fromIO: fromIO2
};
var MonadTask = {
  URI,
  map: _map,
  of: of3,
  ap: _apPar,
  chain: flatMap2,
  fromIO: fromIO2,
  fromTask
};
var FromIO = {
  URI,
  fromIO: fromIO2
};
var FromTask = {
  URI,
  fromIO: fromIO2,
  fromTask
};
var FromReader = {
  URI,
  fromReader: fromReader2
};
var _FlatMap = {
  flatMap: flatMap2
};
var _FromIO = {
  fromIO: FromIO.fromIO
};
var _FromTask = {
  fromTask
};
var _FromReader = {
  fromReader: fromReader2
};
var flatMapIO2 = flatMapIO(_FromIO, _FlatMap);
var flatMapTask2 = flatMapTask(_FromTask, _FlatMap);
var flatMapReader2 = flatMapReader(_FromReader, _FlatMap);
var flatMapReaderIO = /* @__PURE__ */ dual(
  2,
  (self, f) => flatMap2(self, fromReaderIOK(f))
);
var tap2 = /* @__PURE__ */ dual(2, tap(Chain));
var tapIO2 = /* @__PURE__ */ dual(2, tapIO(FromIO, Chain));
var tapReader2 = /* @__PURE__ */ dual(2, tapReader(FromReader, Chain));
var tapTask2 = /* @__PURE__ */ dual(2, tapTask(FromTask, Chain));
var tapReaderIO = /* @__PURE__ */ dual(
  2,
  (self, f) => tap2(self, fromReaderIOK(f))
);
var fromIOK2 = /* @__PURE__ */ fromIOK(FromIO);
var chainIOK = flatMapIO2;
var chainFirstIOK = tapIO2;
var ask2 = /* @__PURE__ */ ask(FromReader);
var asks2 = /* @__PURE__ */ asks(FromReader);
var fromReaderK2 = /* @__PURE__ */ fromReaderK(FromReader);
var chainReaderK = flatMapReader2;
var chainReaderKW = flatMapReader2;
var chainFirstReaderK = tapReader2;
var chainFirstReaderKW = tapReader2;
var fromReaderIOK = (f) => (...a) => fromReaderIO(f(...a));
var chainReaderIOKW = flatMapReaderIO;
var chainReaderIOK = flatMapReaderIO;
var chainFirstReaderIOKW = tapReaderIO;
var chainFirstReaderIOK = tapReaderIO;
var fromTaskK2 = /* @__PURE__ */ fromTaskK(FromTask);
var chainTaskK = flatMapTask2;
var chainFirstTaskK = tapTask2;
var Do = /* @__PURE__ */ of3(emptyRecord);
var bindTo2 = /* @__PURE__ */ bindTo(Functor2);
var let_2 = /* @__PURE__ */ let_(Functor2);
var bind2 = /* @__PURE__ */ bind(Chain);
var bindW = bind2;
var apS2 = /* @__PURE__ */ apS(ApplyPar2);
var apSW = apS2;
var ApT = /* @__PURE__ */ of3(emptyReadonlyArray);
var do_2 = do_(
  Pointed2,
  ChainRec
);
var traverseReadonlyNonEmptyArrayWithIndex3 = (f) => flow(traverseReadonlyNonEmptyArrayWithIndex(f), map(traverseReadonlyNonEmptyArrayWithIndex2(SK)));
var traverseReadonlyArrayWithIndex = (f) => {
  const g = traverseReadonlyNonEmptyArrayWithIndex3(f);
  return (as3) => isNonEmpty(as3) ? g(as3) : ApT;
};
var traverseReadonlyNonEmptyArrayWithIndexSeq2 = (f) => flow(traverseReadonlyNonEmptyArrayWithIndex(f), map(traverseReadonlyNonEmptyArrayWithIndexSeq(SK)));
var traverseReadonlyArrayWithIndexSeq = (f) => {
  const g = traverseReadonlyNonEmptyArrayWithIndexSeq2(f);
  return (as3) => isNonEmpty(as3) ? g(as3) : ApT;
};
var traverseArrayWithIndex = traverseReadonlyArrayWithIndex;
var traverseArray = (f) => traverseReadonlyArrayWithIndex((_, a) => f(a));
var sequenceArray = /* @__PURE__ */ traverseArray(identity);
var traverseSeqArrayWithIndex = traverseReadonlyArrayWithIndexSeq;
var traverseSeqArray = (f) => traverseReadonlyArrayWithIndexSeq((_, a) => f(a));
var chain = flatMap2;
var chainW = flatMap2;
var chainFirst = tap2;
var chainFirstW = tap2;
var sequenceSeqArray = /* @__PURE__ */ traverseSeqArray(identity);
var readerTask = {
  URI,
  map: _map,
  of: of3,
  ap: _apPar,
  chain: flatMap2,
  fromIO: fromIO2,
  fromTask
};
var readerTaskSeq = {
  URI,
  map: _map,
  of: of3,
  ap: _apSeq,
  chain: flatMap2,
  fromIO: fromIO2,
  fromTask
};
var getSemigroup = /* @__PURE__ */ getApplySemigroup(ApplySeq);
var getMonoid = /* @__PURE__ */ getApplicativeMonoid(ApplicativeSeq);
function run(ma, r) {
  return ma(r)();
}

export {
  fromReader2 as fromReader,
  fromTask,
  fromIO2 as fromIO,
  fromReaderIO,
  local2 as local,
  asksReaderTaskW,
  asksReaderTask,
  map3 as map,
  ap2 as ap,
  apW,
  of3 as of,
  flatMap2 as flatMap,
  flattenW,
  flatten,
  URI,
  Functor2 as Functor,
  as2 as as,
  asUnit2 as asUnit,
  flap2 as flap,
  Pointed2 as Pointed,
  ApplyPar2 as ApplyPar,
  apFirst2 as apFirst,
  apSecond2 as apSecond,
  ApplicativePar,
  ApplySeq,
  ApplicativeSeq,
  Chain,
  chainRec,
  ChainRec,
  Monad2 as Monad,
  MonadIO,
  MonadTask,
  FromIO,
  FromTask,
  FromReader,
  flatMapIO2 as flatMapIO,
  flatMapTask2 as flatMapTask,
  flatMapReader2 as flatMapReader,
  flatMapReaderIO,
  tap2 as tap,
  tapIO2 as tapIO,
  tapReader2 as tapReader,
  tapTask2 as tapTask,
  tapReaderIO,
  fromIOK2 as fromIOK,
  chainIOK,
  chainFirstIOK,
  ask2 as ask,
  asks2 as asks,
  fromReaderK2 as fromReaderK,
  chainReaderK,
  chainReaderKW,
  chainFirstReaderK,
  chainFirstReaderKW,
  fromReaderIOK,
  chainReaderIOKW,
  chainReaderIOK,
  chainFirstReaderIOKW,
  chainFirstReaderIOK,
  fromTaskK2 as fromTaskK,
  chainTaskK,
  chainFirstTaskK,
  Do,
  bindTo2 as bindTo,
  let_2 as let_,
  bind2 as bind,
  bindW,
  apS2 as apS,
  apSW,
  ApT,
  do_2 as do_,
  traverseReadonlyNonEmptyArrayWithIndex3 as traverseReadonlyNonEmptyArrayWithIndex,
  traverseReadonlyArrayWithIndex,
  traverseReadonlyNonEmptyArrayWithIndexSeq2 as traverseReadonlyNonEmptyArrayWithIndexSeq,
  traverseReadonlyArrayWithIndexSeq,
  traverseArrayWithIndex,
  traverseArray,
  sequenceArray,
  traverseSeqArrayWithIndex,
  traverseSeqArray,
  chain,
  chainW,
  chainFirst,
  chainFirstW,
  sequenceSeqArray,
  readerTask,
  readerTaskSeq,
  getSemigroup,
  getMonoid,
  run,
  ReaderTask_exports
};
