import {
  ApplyPar,
  ApplySeq,
  Chain,
  Functor as Functor2,
  Monad,
  Pointed,
  of as of2
} from "./chunk-CKHVAAQ5.mjs";
import {
  ask,
  asks,
  fromReaderK,
  tapReader
} from "./chunk-ZUUTK32Y.mjs";
import {
  Apply,
  asksReaderW,
  local,
  map as map2,
  of,
  traverseReadonlyNonEmptyArrayWithIndex
} from "./chunk-AHSGWEN4.mjs";
import {
  bracketW,
  fromEither,
  fromIOEither,
  getApplicativeTaskValidation,
  left as left2,
  leftIO,
  leftTask,
  right as right3,
  rightIO,
  rightTask,
  traverseReadonlyNonEmptyArrayWithIndex as traverseReadonlyNonEmptyArrayWithIndex2,
  traverseReadonlyNonEmptyArrayWithIndexSeq
} from "./chunk-4S2MD6KP.mjs";
import {
  alt,
  altValidation,
  ap as ap2,
  chainNullableK,
  flatMap,
  fromNullable,
  fromNullableK,
  getOrElse,
  left,
  leftF,
  map,
  mapBoth,
  mapError,
  match,
  matchE,
  orElse,
  orLeft,
  right as right2,
  rightF,
  swap,
  tapError,
  toUnion
} from "./chunk-HZOOJZWX.mjs";
import {
  filter,
  filterMap,
  partition,
  partitionMap
} from "./chunk-NNZUJMKX.mjs";
import {
  compact,
  separate
} from "./chunk-47WJXJHK.mjs";
import {
  fromTaskK,
  tapTask
} from "./chunk-WCFCQNDF.mjs";
import {
  ApplicativePar
} from "./chunk-64PLWQD3.mjs";
import {
  fromIOK,
  tapIO
} from "./chunk-TUMMPMRG.mjs";
import {
  Functor,
  do_3 as do_,
  getCompactable,
  getFilterable,
  getSemigroup,
  isLeft,
  isRight,
  right
} from "./chunk-3AL4EMTU.mjs";
import {
  getApplicativeMonoid
} from "./chunk-LN4UQKIO.mjs";
import {
  chainOptionK,
  filterOrElse,
  fromEitherK,
  fromOption,
  fromOptionK,
  fromPredicate,
  tapEither
} from "./chunk-SEYMJLV6.mjs";
import {
  as,
  asUnit,
  bindTo,
  flap,
  let_
} from "./chunk-WKK6AYQI.mjs";
import {
  ap,
  apFirst,
  apS,
  apSecond,
  getApplySemigroup
} from "./chunk-ZMCLCMOU.mjs";
import {
  bind,
  tap
} from "./chunk-MDNVYLGG.mjs";
import {
  emptyReadonlyArray,
  emptyRecord,
  flatMapEither,
  flatMapIO,
  flatMapNullable,
  flatMapOption,
  flatMapReader,
  flatMapTask,
  isNonEmpty,
  liftNullable,
  liftOption
} from "./chunk-WPJQNT3M.mjs";
import {
  SK,
  dual,
  flow,
  identity,
  pipe
} from "./chunk-ZI34HWXZ.mjs";
import {
  __export
} from "./chunk-QK4PKNB3.mjs";

// src/ReaderTaskEither.ts
var ReaderTaskEither_exports = {};
__export(ReaderTaskEither_exports, {
  Alt: () => Alt,
  ApT: () => ApT,
  ApplicativePar: () => ApplicativePar2,
  ApplicativeSeq: () => ApplicativeSeq,
  ApplyPar: () => ApplyPar2,
  ApplySeq: () => ApplySeq2,
  Bifunctor: () => Bifunctor,
  Chain: () => Chain2,
  ChainRec: () => ChainRec,
  Do: () => Do,
  FromEither: () => FromEither,
  FromIO: () => FromIO,
  FromReader: () => FromReader,
  FromTask: () => FromTask,
  Functor: () => Functor3,
  Monad: () => Monad2,
  MonadIO: () => MonadIO,
  MonadTask: () => MonadTask,
  MonadThrow: () => MonadThrow,
  Pointed: () => Pointed2,
  URI: () => URI,
  alt: () => alt2,
  altW: () => altW,
  ap: () => ap3,
  apFirst: () => apFirst2,
  apFirstW: () => apFirstW,
  apS: () => apS2,
  apSW: () => apSW,
  apSecond: () => apSecond2,
  apSecondW: () => apSecondW,
  apW: () => apW,
  as: () => as2,
  asUnit: () => asUnit2,
  ask: () => ask2,
  asks: () => asks2,
  asksReaderTaskEither: () => asksReaderTaskEither,
  asksReaderTaskEitherW: () => asksReaderTaskEitherW,
  bimap: () => bimap,
  bind: () => bind2,
  bindTo: () => bindTo2,
  bindW: () => bindW,
  bracket: () => bracket,
  bracketW: () => bracketW2,
  chain: () => chain,
  chainEitherK: () => chainEitherK,
  chainEitherKW: () => chainEitherKW,
  chainFirst: () => chainFirst,
  chainFirstEitherK: () => chainFirstEitherK,
  chainFirstEitherKW: () => chainFirstEitherKW,
  chainFirstIOK: () => chainFirstIOK,
  chainFirstReaderEitherK: () => chainFirstReaderEitherK,
  chainFirstReaderEitherKW: () => chainFirstReaderEitherKW,
  chainFirstReaderIOK: () => chainFirstReaderIOK,
  chainFirstReaderIOKW: () => chainFirstReaderIOKW,
  chainFirstReaderK: () => chainFirstReaderK,
  chainFirstReaderKW: () => chainFirstReaderKW,
  chainFirstReaderTaskK: () => chainFirstReaderTaskK,
  chainFirstReaderTaskKW: () => chainFirstReaderTaskKW,
  chainFirstTaskEitherK: () => chainFirstTaskEitherK,
  chainFirstTaskEitherKW: () => chainFirstTaskEitherKW,
  chainFirstTaskK: () => chainFirstTaskK,
  chainFirstW: () => chainFirstW,
  chainIOEitherK: () => chainIOEitherK,
  chainIOEitherKW: () => chainIOEitherKW,
  chainIOK: () => chainIOK,
  chainNullableK: () => chainNullableK2,
  chainOptionK: () => chainOptionK2,
  chainOptionKW: () => chainOptionKW,
  chainReaderEitherK: () => chainReaderEitherK,
  chainReaderEitherKW: () => chainReaderEitherKW,
  chainReaderIOK: () => chainReaderIOK,
  chainReaderIOKW: () => chainReaderIOKW,
  chainReaderK: () => chainReaderK,
  chainReaderKW: () => chainReaderKW,
  chainReaderTaskK: () => chainReaderTaskK,
  chainReaderTaskKW: () => chainReaderTaskKW,
  chainRec: () => chainRec,
  chainTaskEitherK: () => chainTaskEitherK,
  chainTaskEitherKW: () => chainTaskEitherKW,
  chainTaskK: () => chainTaskK,
  chainW: () => chainW,
  do: () => do_2,
  filterOrElse: () => filterOrElse2,
  filterOrElseW: () => filterOrElseW,
  flap: () => flap2,
  flatMap: () => flatMap2,
  flatMapEither: () => flatMapEither2,
  flatMapIO: () => flatMapIO2,
  flatMapIOEither: () => flatMapIOEither,
  flatMapNullable: () => flatMapNullable2,
  flatMapOption: () => flatMapOption2,
  flatMapReader: () => flatMapReader2,
  flatMapReaderEither: () => flatMapReaderEither,
  flatMapReaderIO: () => flatMapReaderIO,
  flatMapReaderTask: () => flatMapReaderTask,
  flatMapTask: () => flatMapTask2,
  flatMapTaskEither: () => flatMapTaskEither,
  flatten: () => flatten,
  flattenW: () => flattenW,
  fold: () => fold,
  foldW: () => foldW,
  fromEither: () => fromEither2,
  fromEitherK: () => fromEitherK2,
  fromIO: () => fromIO,
  fromIOEither: () => fromIOEither2,
  fromIOEitherK: () => fromIOEitherK,
  fromIOK: () => fromIOK2,
  fromNullable: () => fromNullable2,
  fromNullableK: () => fromNullableK2,
  fromOption: () => fromOption2,
  fromOptionK: () => fromOptionK2,
  fromPredicate: () => fromPredicate2,
  fromReader: () => fromReader,
  fromReaderEither: () => fromReaderEither,
  fromReaderEitherK: () => fromReaderEitherK,
  fromReaderIOK: () => fromReaderIOK,
  fromReaderK: () => fromReaderK2,
  fromReaderTaskK: () => fromReaderTaskK,
  fromTask: () => fromTask,
  fromTaskEither: () => fromTaskEither,
  fromTaskEitherK: () => fromTaskEitherK,
  fromTaskK: () => fromTaskK2,
  getAltReaderTaskValidation: () => getAltReaderTaskValidation,
  getApplicativeReaderTaskValidation: () => getApplicativeReaderTaskValidation,
  getApplyMonoid: () => getApplyMonoid,
  getApplySemigroup: () => getApplySemigroup2,
  getCompactable: () => getCompactable2,
  getFilterable: () => getFilterable2,
  getOrElse: () => getOrElse2,
  getOrElseW: () => getOrElseW,
  getReaderTaskValidation: () => getReaderTaskValidation,
  getSemigroup: () => getSemigroup2,
  left: () => left3,
  leftIO: () => leftIO2,
  leftReader: () => leftReader,
  leftReaderIO: () => leftReaderIO,
  leftReaderTask: () => leftReaderTask,
  leftTask: () => leftTask2,
  let: () => let_2,
  liftNullable: () => liftNullable2,
  liftOption: () => liftOption2,
  local: () => local2,
  map: () => map3,
  mapBoth: () => mapBoth2,
  mapError: () => mapError2,
  mapLeft: () => mapLeft,
  match: () => match2,
  matchE: () => matchE2,
  matchEW: () => matchEW,
  matchW: () => matchW,
  of: () => of3,
  orElse: () => orElse2,
  orElseFirst: () => orElseFirst,
  orElseFirstW: () => orElseFirstW,
  orElseW: () => orElseW,
  orLeft: () => orLeft2,
  readerTaskEither: () => readerTaskEither,
  readerTaskEitherSeq: () => readerTaskEitherSeq,
  right: () => right4,
  rightIO: () => rightIO2,
  rightReader: () => rightReader,
  rightReaderIO: () => rightReaderIO,
  rightReaderTask: () => rightReaderTask,
  rightTask: () => rightTask2,
  run: () => run,
  sequenceArray: () => sequenceArray,
  sequenceSeqArray: () => sequenceSeqArray,
  swap: () => swap2,
  tap: () => tap2,
  tapEither: () => tapEither2,
  tapError: () => tapError2,
  tapIO: () => tapIO2,
  tapReader: () => tapReader2,
  tapReaderEither: () => tapReaderEither,
  tapReaderIO: () => tapReaderIO,
  tapReaderTask: () => tapReaderTask,
  tapTask: () => tapTask2,
  tapTaskEither: () => tapTaskEither,
  throwError: () => throwError,
  toUnion: () => toUnion2,
  traverseArray: () => traverseArray,
  traverseArrayWithIndex: () => traverseArrayWithIndex,
  traverseReadonlyArrayWithIndex: () => traverseReadonlyArrayWithIndex,
  traverseReadonlyArrayWithIndexSeq: () => traverseReadonlyArrayWithIndexSeq,
  traverseReadonlyNonEmptyArrayWithIndex: () => traverseReadonlyNonEmptyArrayWithIndex3,
  traverseReadonlyNonEmptyArrayWithIndexSeq: () => traverseReadonlyNonEmptyArrayWithIndexSeq2,
  traverseSeqArray: () => traverseSeqArray,
  traverseSeqArrayWithIndex: () => traverseSeqArrayWithIndex
});
var fromTaskEither = of;
var left3 = /* @__PURE__ */ left(Pointed);
var right4 = /* @__PURE__ */ right2(Pointed);
var rightTask2 = /* @__PURE__ */ flow(
  rightTask,
  fromTaskEither
);
var leftTask2 = /* @__PURE__ */ flow(
  leftTask,
  fromTaskEither
);
var rightReader = (ma) => flow(ma, right3);
var leftReader = (me) => flow(me, left2);
var rightReaderTask = /* @__PURE__ */ rightF(Functor2);
var leftReaderTask = /* @__PURE__ */ leftF(Functor2);
var rightIO2 = /* @__PURE__ */ flow(
  rightIO,
  fromTaskEither
);
var leftIO2 = /* @__PURE__ */ flow(
  leftIO,
  fromTaskEither
);
var rightReaderIO = (ma) => flow(ma, rightIO);
var leftReaderIO = (me) => flow(me, leftIO);
var fromEither2 = of2;
var fromReader = rightReader;
var fromIO = rightIO2;
var fromTask = rightTask2;
var fromIOEither2 = /* @__PURE__ */ flow(
  fromIOEither,
  fromTaskEither
);
var fromReaderEither = (ma) => flow(ma, fromEither);
var match2 = /* @__PURE__ */ match(Functor2);
var matchW = match2;
var matchE2 = /* @__PURE__ */ matchE(Chain);
var fold = matchE2;
var matchEW = matchE2;
var foldW = matchEW;
var getOrElse2 = /* @__PURE__ */ getOrElse(Monad);
var getOrElseW = getOrElse2;
var toUnion2 = /* @__PURE__ */ toUnion(
  Functor2
);
var fromNullable2 = /* @__PURE__ */ fromNullable(Pointed);
var fromNullableK2 = /* @__PURE__ */ fromNullableK(Pointed);
var chainNullableK2 = /* @__PURE__ */ chainNullableK(
  Monad
);
var local2 = local;
var asksReaderTaskEitherW = asksReaderW;
var asksReaderTaskEither = asksReaderTaskEitherW;
var orElse2 = /* @__PURE__ */ orElse(Monad);
var orElseW = orElse2;
var tapError2 = /* @__PURE__ */ dual(2, tapError(Monad));
var orLeft2 = /* @__PURE__ */ orLeft(Monad);
var swap2 = /* @__PURE__ */ swap(
  Functor2
);
var fromIOEitherK = (f) => flow(f, fromIOEither2);
var fromTaskEitherK = (f) => flow(f, fromTaskEither);
var fromReaderEitherK = (f) => flow(f, fromReaderEither);
var _map = (fa, f) => pipe(fa, map3(f));
var _apPar = (fab, fa) => pipe(fab, ap3(fa));
var _apSeq = (fab, fa) => flatMap2(fab, (f) => pipe(fa, map3(f)));
var _alt = (fa, that) => pipe(fa, alt2(that));
var map3 = /* @__PURE__ */ map(Functor2);
var mapBoth2 = /* @__PURE__ */ dual(3, mapBoth(Functor2));
var bimap = mapBoth2;
var mapError2 = /* @__PURE__ */ dual(2, mapError(Functor2));
var mapLeft = mapError2;
var ap3 = /* @__PURE__ */ ap2(ApplyPar);
var apW = ap3;
var of3 = right4;
var flatMap2 = /* @__PURE__ */ dual(2, flatMap(Monad));
var flattenW = /* @__PURE__ */ flatMap2(identity);
var flatten = flattenW;
var alt2 = /* @__PURE__ */ alt(Monad);
var altW = alt2;
var throwError = left3;
var URI = "ReaderTaskEither";
var getCompactable2 = (M) => {
  const C = getCompactable(M);
  return {
    URI,
    _E: void 0,
    compact: compact(Functor2, C),
    separate: separate(Functor2, C, Functor)
  };
};
function getFilterable2(M) {
  const F = getFilterable(M);
  const C = getCompactable2(M);
  const filter2 = filter(Functor2, F);
  const filterMap2 = filterMap(Functor2, F);
  const partition2 = partition(Functor2, F);
  const partitionMap2 = partitionMap(Functor2, F);
  return {
    URI,
    _E: void 0,
    map: _map,
    compact: C.compact,
    separate: C.separate,
    filter: (fa, predicate) => pipe(fa, filter2(predicate)),
    filterMap: (fa, f) => pipe(fa, filterMap2(f)),
    partition: (fa, predicate) => pipe(fa, partition2(predicate)),
    partitionMap: (fa, f) => pipe(fa, partitionMap2(f))
  };
}
function getApplicativeReaderTaskValidation(A, S) {
  const ap4 = ap(Apply, getApplicativeTaskValidation(A, S));
  return {
    URI,
    _E: void 0,
    map: _map,
    ap: (fab, fa) => pipe(fab, ap4(fa)),
    of: of3
  };
}
function getAltReaderTaskValidation(S) {
  const alt3 = altValidation(Monad, S);
  return {
    URI,
    _E: void 0,
    map: _map,
    alt: (fa, that) => pipe(fa, alt3(that))
  };
}
var Functor3 = {
  URI,
  map: _map
};
var as2 = dual(2, as(Functor3));
var asUnit2 = asUnit(Functor3);
var flap2 = /* @__PURE__ */ flap(Functor3);
var Pointed2 = {
  URI,
  of: of3
};
var ApplyPar2 = {
  URI,
  map: _map,
  ap: _apPar
};
var apFirst2 = /* @__PURE__ */ apFirst(ApplyPar2);
var apFirstW = apFirst2;
var apSecond2 = /* @__PURE__ */ apSecond(ApplyPar2);
var apSecondW = apSecond2;
var ApplicativePar2 = {
  URI,
  map: _map,
  ap: _apPar,
  of: of3
};
var ApplySeq2 = {
  URI,
  map: _map,
  ap: _apSeq
};
var ApplicativeSeq = {
  URI,
  map: _map,
  ap: _apSeq,
  of: of3
};
var Chain2 = {
  URI,
  map: _map,
  ap: _apPar,
  chain: flatMap2
};
var chainRec = (a, f) => (r) => async () => {
  let current = await f(a)(r)();
  while (true) {
    if (isRight(current) && isLeft(current.right)) {
      current = await f(current.right.left)(r)();
      continue;
    }
    if (isLeft(current)) {
      return current;
    }
    if (isRight(current.right)) {
      return right(current.right.right);
    }
  }
};
var ChainRec = {
  ...Chain2,
  chainRec
};
var Monad2 = {
  URI,
  map: _map,
  ap: _apPar,
  chain: flatMap2,
  of: of3
};
var MonadIO = {
  URI,
  map: _map,
  ap: _apPar,
  chain: flatMap2,
  of: of3,
  fromIO
};
var MonadTask = {
  URI,
  map: _map,
  ap: _apPar,
  chain: flatMap2,
  of: of3,
  fromIO,
  fromTask
};
var MonadThrow = {
  URI,
  map: _map,
  ap: _apPar,
  chain: flatMap2,
  of: of3,
  throwError
};
var FromEither = {
  URI,
  fromEither: fromEither2
};
var FromIO = {
  URI,
  fromIO
};
var FromTask = {
  URI,
  fromIO,
  fromTask
};
var FromReader = {
  URI,
  fromReader
};
var tap2 = /* @__PURE__ */ dual(2, tap(Chain2));
var tapEither2 = /* @__PURE__ */ dual(2, tapEither(FromEither, Chain2));
var tapIO2 = /* @__PURE__ */ dual(2, tapIO(FromIO, Chain2));
var tapTask2 = /* @__PURE__ */ dual(2, tapTask(FromTask, Chain2));
var tapReader2 = /* @__PURE__ */ dual(2, tapReader(FromReader, Chain2));
var tapReaderEither = /* @__PURE__ */ dual(
  2,
  (self, f) => tap2(self, fromReaderEitherK(f))
);
var tapTaskEither = /* @__PURE__ */ dual(
  2,
  (self, f) => tap2(self, fromTaskEitherK(f))
);
var tapReaderTask = /* @__PURE__ */ dual(
  2,
  (self, f) => tap2(self, fromReaderTaskK(f))
);
var tapReaderIO = /* @__PURE__ */ dual(
  2,
  (self, f) => tap2(self, fromReaderIOK(f))
);
var Bifunctor = {
  URI,
  bimap: mapBoth2,
  mapLeft: mapError2
};
var Alt = {
  URI,
  map: _map,
  alt: _alt
};
var ask2 = /* @__PURE__ */ ask(FromReader);
var asks2 = /* @__PURE__ */ asks(FromReader);
var fromReaderK2 = /* @__PURE__ */ fromReaderK(FromReader);
var chainFirstReaderK = tapReader2;
var chainFirstReaderKW = tapReader2;
var chainFirstReaderEitherKW = tapReaderEither;
var chainFirstReaderEitherK = tapReaderEither;
var chainFirstTaskEitherKW = tapTaskEither;
var chainFirstTaskEitherK = tapTaskEither;
var fromReaderTaskK = (f) => (...a) => rightReaderTask(f(...a));
var chainFirstReaderTaskKW = tapReaderTask;
var chainFirstReaderTaskK = tapReaderTask;
var fromReaderIOK = (f) => (...a) => rightReaderIO(f(...a));
var chainFirstReaderIOKW = tapReaderIO;
var chainFirstReaderIOK = tapReaderIO;
var fromOption2 = /* @__PURE__ */ fromOption(FromEither);
var fromOptionK2 = /* @__PURE__ */ fromOptionK(FromEither);
var chainOptionK2 = /* @__PURE__ */ chainOptionK(FromEither, Chain2);
var chainOptionKW = chainOptionK2;
var _FromEither = {
  fromEither: FromEither.fromEither
};
var liftNullable2 = /* @__PURE__ */ liftNullable(_FromEither);
var liftOption2 = /* @__PURE__ */ liftOption(_FromEither);
var _FlatMap = {
  flatMap: flatMap2
};
var _FromIO = {
  fromIO
};
var _FromTask = {
  fromTask
};
var _FromReader = {
  fromReader
};
var flatMapNullable2 = /* @__PURE__ */ flatMapNullable(_FromEither, _FlatMap);
var flatMapOption2 = /* @__PURE__ */ flatMapOption(_FromEither, _FlatMap);
var flatMapEither2 = /* @__PURE__ */ flatMapEither(_FromEither, _FlatMap);
var flatMapTaskEither = /* @__PURE__ */ dual(
  2,
  (self, f) => flatMap2(self, fromTaskEitherK(f))
);
var flatMapReaderTask = /* @__PURE__ */ dual(
  2,
  (self, f) => flatMap2(self, fromReaderTaskK(f))
);
var flatMapIO2 = /* @__PURE__ */ flatMapIO(_FromIO, _FlatMap);
var flatMapTask2 = /* @__PURE__ */ flatMapTask(_FromTask, _FlatMap);
var flatMapReader2 = /* @__PURE__ */ flatMapReader(_FromReader, _FlatMap);
var flatMapReaderIO = /* @__PURE__ */ dual(
  2,
  (self, f) => flatMap2(self, fromReaderIOK(f))
);
var flatMapIOEither = /* @__PURE__ */ dual(
  2,
  (self, f) => flatMap2(self, fromIOEitherK(f))
);
var flatMapReaderEither = /* @__PURE__ */ dual(
  2,
  (self, f) => flatMap2(self, fromReaderEitherK(f))
);
var chainEitherK = flatMapEither2;
var chainEitherKW = flatMapEither2;
var chainFirstEitherK = tapEither2;
var chainFirstEitherKW = tapEither2;
var chainTaskEitherKW = flatMapTaskEither;
var chainTaskEitherK = flatMapTaskEither;
var chainReaderTaskKW = flatMapReaderTask;
var chainReaderTaskK = flatMapReaderTask;
var fromPredicate2 = /* @__PURE__ */ fromPredicate(FromEither);
var filterOrElse2 = /* @__PURE__ */ filterOrElse(FromEither, Chain2);
var filterOrElseW = filterOrElse2;
var fromEitherK2 = /* @__PURE__ */ fromEitherK(FromEither);
var fromIOK2 = /* @__PURE__ */ fromIOK(FromIO);
var chainIOK = flatMapIO2;
var chainFirstIOK = tapIO2;
var fromTaskK2 = /* @__PURE__ */ fromTaskK(FromTask);
var chainTaskK = flatMapTask2;
var chainFirstTaskK = tapTask2;
var chainReaderK = flatMapReader2;
var chainReaderKW = flatMapReader2;
var chainReaderIOKW = flatMapReaderIO;
var chainReaderIOK = flatMapReaderIO;
var chainIOEitherKW = flatMapIOEither;
var chainIOEitherK = flatMapIOEither;
var chainReaderEitherKW = flatMapReaderEither;
var chainReaderEitherK = flatMapReaderEither;
function bracket(acquire, use, release) {
  return bracketW2(acquire, use, release);
}
function bracketW2(acquire, use, release) {
  return (r) => bracketW(
    acquire(r),
    (a) => use(a)(r),
    (a, e) => release(a, e)(r)
  );
}
var Do = /* @__PURE__ */ of3(emptyRecord);
var bindTo2 = /* @__PURE__ */ bindTo(Functor3);
var let_2 = /* @__PURE__ */ let_(Functor3);
var bind2 = /* @__PURE__ */ bind(Chain2);
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), map2(traverseReadonlyNonEmptyArrayWithIndex2(SK)));
var traverseReadonlyArrayWithIndex = (f) => {
  const g = traverseReadonlyNonEmptyArrayWithIndex3(f);
  return (as3) => isNonEmpty(as3) ? g(as3) : ApT;
};
var traverseReadonlyNonEmptyArrayWithIndexSeq2 = (f) => flow(traverseReadonlyNonEmptyArrayWithIndex(f), map2(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 sequenceSeqArray = /* @__PURE__ */ traverseSeqArray(identity);
var chain = flatMap2;
var chainW = flatMap2;
var chainFirst = tap2;
var chainFirstW = tap2;
var orElseFirst = tapError2;
var orElseFirstW = tapError2;
var readerTaskEither = {
  URI,
  map: _map,
  of: of3,
  ap: _apPar,
  chain: flatMap2,
  alt: _alt,
  bimap: mapBoth2,
  mapLeft: mapError2,
  fromIO,
  fromTask,
  throwError
};
var readerTaskEitherSeq = {
  URI,
  map: _map,
  of: of3,
  ap: _apSeq,
  chain: flatMap2,
  alt: _alt,
  bimap: mapBoth2,
  mapLeft: mapError2,
  fromIO,
  fromTask,
  throwError
};
var getApplySemigroup2 = /* @__PURE__ */ getApplySemigroup(ApplySeq2);
var getApplyMonoid = /* @__PURE__ */ getApplicativeMonoid(ApplicativeSeq);
var getSemigroup2 = (S) => getApplySemigroup(ApplySeq)(getSemigroup(S));
function getReaderTaskValidation(SE) {
  const applicativeReaderTaskValidation = getApplicativeReaderTaskValidation(ApplicativePar, SE);
  const altReaderTaskValidation = getAltReaderTaskValidation(SE);
  return {
    URI,
    _E: void 0,
    map: _map,
    of: of3,
    chain: flatMap2,
    bimap: mapBoth2,
    mapLeft: mapError2,
    ap: applicativeReaderTaskValidation.ap,
    alt: altReaderTaskValidation.alt,
    fromIO,
    fromTask,
    throwError
  };
}
function run(ma, r) {
  return ma(r)();
}

export {
  fromTaskEither,
  left3 as left,
  right4 as right,
  rightTask2 as rightTask,
  leftTask2 as leftTask,
  rightReader,
  leftReader,
  rightReaderTask,
  leftReaderTask,
  rightIO2 as rightIO,
  leftIO2 as leftIO,
  rightReaderIO,
  leftReaderIO,
  fromEither2 as fromEither,
  fromReader,
  fromIO,
  fromTask,
  fromIOEither2 as fromIOEither,
  fromReaderEither,
  match2 as match,
  matchW,
  matchE2 as matchE,
  fold,
  matchEW,
  foldW,
  getOrElse2 as getOrElse,
  getOrElseW,
  toUnion2 as toUnion,
  fromNullable2 as fromNullable,
  fromNullableK2 as fromNullableK,
  chainNullableK2 as chainNullableK,
  local2 as local,
  asksReaderTaskEitherW,
  asksReaderTaskEither,
  orElse2 as orElse,
  orElseW,
  tapError2 as tapError,
  orLeft2 as orLeft,
  swap2 as swap,
  fromIOEitherK,
  fromTaskEitherK,
  fromReaderEitherK,
  map3 as map,
  mapBoth2 as mapBoth,
  bimap,
  mapError2 as mapError,
  mapLeft,
  ap3 as ap,
  apW,
  of3 as of,
  flatMap2 as flatMap,
  flattenW,
  flatten,
  alt2 as alt,
  altW,
  throwError,
  URI,
  getCompactable2 as getCompactable,
  getFilterable2 as getFilterable,
  getApplicativeReaderTaskValidation,
  getAltReaderTaskValidation,
  Functor3 as Functor,
  as2 as as,
  asUnit2 as asUnit,
  flap2 as flap,
  Pointed2 as Pointed,
  ApplyPar2 as ApplyPar,
  apFirst2 as apFirst,
  apFirstW,
  apSecond2 as apSecond,
  apSecondW,
  ApplicativePar2 as ApplicativePar,
  ApplySeq2 as ApplySeq,
  ApplicativeSeq,
  Chain2 as Chain,
  chainRec,
  ChainRec,
  Monad2 as Monad,
  MonadIO,
  MonadTask,
  MonadThrow,
  FromEither,
  FromIO,
  FromTask,
  FromReader,
  tap2 as tap,
  tapEither2 as tapEither,
  tapIO2 as tapIO,
  tapTask2 as tapTask,
  tapReader2 as tapReader,
  tapReaderEither,
  tapTaskEither,
  tapReaderTask,
  tapReaderIO,
  Bifunctor,
  Alt,
  ask2 as ask,
  asks2 as asks,
  fromReaderK2 as fromReaderK,
  chainFirstReaderK,
  chainFirstReaderKW,
  chainFirstReaderEitherKW,
  chainFirstReaderEitherK,
  chainFirstTaskEitherKW,
  chainFirstTaskEitherK,
  fromReaderTaskK,
  chainFirstReaderTaskKW,
  chainFirstReaderTaskK,
  fromReaderIOK,
  chainFirstReaderIOKW,
  chainFirstReaderIOK,
  fromOption2 as fromOption,
  fromOptionK2 as fromOptionK,
  chainOptionK2 as chainOptionK,
  chainOptionKW,
  liftNullable2 as liftNullable,
  liftOption2 as liftOption,
  flatMapNullable2 as flatMapNullable,
  flatMapOption2 as flatMapOption,
  flatMapEither2 as flatMapEither,
  flatMapTaskEither,
  flatMapReaderTask,
  flatMapIO2 as flatMapIO,
  flatMapTask2 as flatMapTask,
  flatMapReader2 as flatMapReader,
  flatMapReaderIO,
  flatMapIOEither,
  flatMapReaderEither,
  chainEitherK,
  chainEitherKW,
  chainFirstEitherK,
  chainFirstEitherKW,
  chainTaskEitherKW,
  chainTaskEitherK,
  chainReaderTaskKW,
  chainReaderTaskK,
  fromPredicate2 as fromPredicate,
  filterOrElse2 as filterOrElse,
  filterOrElseW,
  fromEitherK2 as fromEitherK,
  fromIOK2 as fromIOK,
  chainIOK,
  chainFirstIOK,
  fromTaskK2 as fromTaskK,
  chainTaskK,
  chainFirstTaskK,
  chainReaderK,
  chainReaderKW,
  chainReaderIOKW,
  chainReaderIOK,
  chainIOEitherKW,
  chainIOEitherK,
  chainReaderEitherKW,
  chainReaderEitherK,
  bracket,
  bracketW2 as bracketW,
  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,
  sequenceSeqArray,
  chain,
  chainW,
  chainFirst,
  chainFirstW,
  orElseFirst,
  orElseFirstW,
  readerTaskEither,
  readerTaskEitherSeq,
  getApplySemigroup2 as getApplySemigroup,
  getApplyMonoid,
  getSemigroup2 as getSemigroup,
  getReaderTaskValidation,
  run,
  ReaderTaskEither_exports
};
