import {
  Apply,
  Chain,
  Functor as Functor2,
  Monad,
  Pointed,
  map,
  of,
  traverseReadonlyNonEmptyArrayWithIndex as traverseReadonlyNonEmptyArrayWithIndex2
} from "./chunk-DHOW4GBY.mjs";
import {
  alt,
  ap,
  chainNullableK,
  flatMap,
  fromEither as fromEither2,
  fromF,
  fromNullable,
  fromNullableK,
  fromOptionK,
  fromPredicate,
  getOrElse,
  map as map2,
  match,
  matchE,
  some as some2,
  zero
} from "./chunk-S7TLXYLA.mjs";
import {
  filter,
  filterMap,
  partition,
  partitionMap
} from "./chunk-NNZUJMKX.mjs";
import {
  compact,
  separate
} from "./chunk-47WJXJHK.mjs";
import {
  fromIOK,
  tapIO
} from "./chunk-TUMMPMRG.mjs";
import {
  Compactable,
  Filterable,
  Functor2 as Functor,
  do_3 as do_,
  fromEither,
  isNone,
  isSome,
  some,
  toNullable,
  toUndefined,
  traverseReadonlyNonEmptyArrayWithIndex2 as traverseReadonlyNonEmptyArrayWithIndex
} from "./chunk-3AL4EMTU.mjs";
import {
  fromEitherK,
  tapEither
} from "./chunk-SEYMJLV6.mjs";
import {
  guard
} from "./chunk-OVCPI5FM.mjs";
import {
  as,
  asUnit,
  bindTo,
  flap,
  let_
} from "./chunk-WKK6AYQI.mjs";
import {
  apFirst,
  apS,
  apSecond
} from "./chunk-ZMCLCMOU.mjs";
import {
  bind,
  tap
} from "./chunk-MDNVYLGG.mjs";
import {
  emptyReadonlyArray,
  emptyRecord,
  flatMapEither,
  flatMapIO,
  isLeft,
  isNonEmpty,
  isRight
} from "./chunk-WPJQNT3M.mjs";
import {
  SK,
  dual,
  flow,
  identity,
  pipe
} from "./chunk-ZI34HWXZ.mjs";
import {
  __export
} from "./chunk-QK4PKNB3.mjs";

// src/IOOption.ts
var IOOption_exports = {};
__export(IOOption_exports, {
  Alt: () => Alt,
  Alternative: () => Alternative,
  ApT: () => ApT,
  Applicative: () => Applicative,
  Apply: () => Apply2,
  Chain: () => Chain2,
  ChainRec: () => ChainRec,
  Compactable: () => Compactable2,
  Do: () => Do,
  Filterable: () => Filterable2,
  FromEither: () => FromEither,
  FromIO: () => FromIO,
  Functor: () => Functor3,
  Monad: () => Monad2,
  MonadIO: () => MonadIO,
  MonadThrow: () => MonadThrow,
  Pointed: () => Pointed2,
  URI: () => URI,
  Zero: () => Zero,
  alt: () => alt2,
  altW: () => altW,
  ap: () => ap2,
  apFirst: () => apFirst2,
  apS: () => apS2,
  apSecond: () => apSecond2,
  as: () => as2,
  asUnit: () => asUnit2,
  bind: () => bind2,
  bindTo: () => bindTo2,
  chain: () => chain,
  chainEitherK: () => chainEitherK,
  chainFirst: () => chainFirst,
  chainFirstEitherK: () => chainFirstEitherK,
  chainFirstIOK: () => chainFirstIOK,
  chainIOK: () => chainIOK,
  chainNullableK: () => chainNullableK2,
  chainOptionK: () => chainOptionK,
  chainRec: () => chainRec,
  compact: () => compact2,
  do: () => do_2,
  filter: () => filter2,
  filterMap: () => filterMap2,
  flap: () => flap2,
  flatMap: () => flatMap2,
  flatMapEither: () => flatMapEither2,
  flatMapIO: () => flatMapIO2,
  flatMapNullable: () => flatMapNullable,
  flatMapOption: () => flatMapOption,
  flatten: () => flatten,
  fold: () => fold,
  fromEither: () => fromEither3,
  fromEitherK: () => fromEitherK2,
  fromIO: () => fromIO,
  fromIOEither: () => fromIOEither,
  fromIOK: () => fromIOK2,
  fromNullable: () => fromNullable2,
  fromNullableK: () => fromNullableK2,
  fromOption: () => fromOption,
  fromOptionK: () => fromOptionK2,
  fromPredicate: () => fromPredicate2,
  getOrElse: () => getOrElse2,
  getOrElseW: () => getOrElseW,
  guard: () => guard2,
  let: () => let_2,
  map: () => map3,
  match: () => match2,
  matchE: () => matchE2,
  matchEW: () => matchEW,
  matchW: () => matchW,
  none: () => none,
  of: () => of2,
  partition: () => partition2,
  partitionMap: () => partitionMap2,
  separate: () => separate2,
  some: () => some3,
  tap: () => tap2,
  tapEither: () => tapEither2,
  tapIO: () => tapIO2,
  throwError: () => throwError,
  toNullable: () => toNullable2,
  toUndefined: () => toUndefined2,
  traverseReadonlyArrayWithIndex: () => traverseReadonlyArrayWithIndex,
  traverseReadonlyNonEmptyArrayWithIndex: () => traverseReadonlyNonEmptyArrayWithIndex3,
  zero: () => zero2
});
var some3 = /* @__PURE__ */ some2(Pointed);
var fromPredicate2 = /* @__PURE__ */ fromPredicate(Pointed);
var fromOption = of;
var fromEither3 = /* @__PURE__ */ fromEither2(Pointed);
var fromIO = /* @__PURE__ */ fromF(Functor2);
var fromIOEither = /* @__PURE__ */ map(fromEither);
var match2 = /* @__PURE__ */ match(
  Functor2
);
var matchW = match2;
var matchE2 = /* @__PURE__ */ matchE(Chain);
var fold = matchE2;
var matchEW = matchE2;
var getOrElse2 = /* @__PURE__ */ getOrElse(Monad);
var getOrElseW = getOrElse2;
var toUndefined2 = map(toUndefined);
var toNullable2 = map(toNullable);
var fromNullable2 = /* @__PURE__ */ fromNullable(Pointed);
var fromNullableK2 = /* @__PURE__ */ fromNullableK(Pointed);
var chainNullableK2 = /* @__PURE__ */ chainNullableK(Monad);
var fromOptionK2 = /* @__PURE__ */ fromOptionK(Pointed);
var map3 = /* @__PURE__ */ map2(Functor2);
var ap2 = /* @__PURE__ */ ap(Apply);
var of2 = some3;
var flatMap2 = /* @__PURE__ */ dual(2, flatMap(Monad));
var flatten = /* @__PURE__ */ flatMap2(identity);
var alt2 = /* @__PURE__ */ alt(
  Monad
);
var altW = alt2;
var zero2 = /* @__PURE__ */ zero(Pointed);
var throwError = zero2;
var none = /* @__PURE__ */ zero2();
var compact2 = /* @__PURE__ */ compact(Functor2, Compactable);
var separate2 = /* @__PURE__ */ separate(Functor2, Compactable, Functor);
var filter2 = /* @__PURE__ */ filter(Functor2, Filterable);
var filterMap2 = /* @__PURE__ */ filterMap(
  Functor2,
  Filterable
);
var partition2 = /* @__PURE__ */ partition(Functor2, Filterable);
var partitionMap2 = /* @__PURE__ */ partitionMap(Functor2, Filterable);
var _map = (fa, f) => pipe(fa, map3(f));
var _ap = (fab, fa) => pipe(fab, ap2(fa));
var _alt = (fa, that) => pipe(fa, alt2(that));
var _filter = (fa, predicate) => pipe(fa, filter2(predicate));
var _filterMap = (fa, f) => pipe(fa, filterMap2(f));
var _partition = (fa, predicate) => pipe(fa, partition2(predicate));
var _partitionMap = (fa, f) => pipe(fa, partitionMap2(f));
var URI = "IOOption";
var Functor3 = {
  URI,
  map: _map
};
var as2 = dual(2, as(Functor3));
var asUnit2 = asUnit(Functor3);
var flap2 = /* @__PURE__ */ flap(Functor3);
var Pointed2 = {
  URI,
  of: of2
};
var Apply2 = {
  URI,
  map: _map,
  ap: _ap
};
var apFirst2 = /* @__PURE__ */ apFirst(Apply2);
var apSecond2 = /* @__PURE__ */ apSecond(Apply2);
var Applicative = {
  URI,
  map: _map,
  ap: _ap,
  of: of2
};
var Chain2 = {
  URI,
  map: _map,
  ap: _ap,
  chain: flatMap2
};
var chainRec = (a, f) => () => {
  let current = f(a)();
  while (true) {
    if (isSome(current) && isLeft(current.value)) {
      current = f(current.value.left)();
      continue;
    }
    if (isNone(current)) {
      return current;
    }
    if (isRight(current.value)) {
      return some(current.value.right);
    }
  }
};
var ChainRec = {
  ...Chain2,
  chainRec
};
var FromEither = {
  URI,
  fromEither: fromEither3
};
var FromIO = {
  URI,
  fromIO
};
var tap2 = /* @__PURE__ */ dual(2, tap(Chain2));
var tapEither2 = /* @__PURE__ */ dual(2, tapEither(FromEither, Chain2));
var tapIO2 = /* @__PURE__ */ dual(2, tapIO(FromIO, Chain2));
var Alt = {
  URI,
  map: _map,
  alt: _alt
};
var Zero = {
  URI,
  zero: zero2
};
var guard2 = /* @__PURE__ */ guard(Zero, Pointed2);
var Alternative = {
  URI,
  map: _map,
  ap: _ap,
  of: of2,
  alt: _alt,
  zero: zero2
};
var Monad2 = {
  URI,
  map: _map,
  ap: _ap,
  of: of2,
  chain: flatMap2
};
var MonadIO = {
  URI,
  map: _map,
  ap: _ap,
  of: of2,
  chain: flatMap2,
  fromIO
};
var MonadThrow = {
  ...Monad2,
  throwError
};
var Compactable2 = {
  URI,
  compact: compact2,
  separate: separate2
};
var Filterable2 = {
  URI,
  map: _map,
  compact: compact2,
  separate: separate2,
  filter: _filter,
  filterMap: _filterMap,
  partition: _partition,
  partitionMap: _partitionMap
};
var _FlatMap = {
  flatMap: flatMap2
};
var _FromIO = {
  fromIO: FromIO.fromIO
};
var _FromEither = {
  fromEither: fromEither3
};
var flatMapIO2 = flatMapIO(_FromIO, _FlatMap);
var flatMapOption = /* @__PURE__ */ dual(
  2,
  (self, f) => flatMap2(self, fromOptionK2(f))
);
var flatMapEither2 = /* @__PURE__ */ flatMapEither(_FromEither, _FlatMap);
var flatMapNullable = /* @__PURE__ */ dual(
  2,
  (self, f) => flatMap2(self, fromNullableK2(f))
);
var fromIOK2 = /* @__PURE__ */ fromIOK(FromIO);
var chainIOK = flatMapIO2;
var chainFirstIOK = tapIO2;
var fromEitherK2 = /* @__PURE__ */ fromEitherK(FromEither);
var chainEitherK = flatMapEither2;
var chainFirstEitherK = tapEither2;
var chainOptionK = flatMapOption;
var Do = /* @__PURE__ */ of2(emptyRecord);
var bindTo2 = /* @__PURE__ */ bindTo(Functor3);
var let_2 = /* @__PURE__ */ let_(Functor3);
var bind2 = /* @__PURE__ */ bind(Chain2);
var apS2 = /* @__PURE__ */ apS(Apply2);
var ApT = /* @__PURE__ */ of2(emptyReadonlyArray);
var do_2 = do_(Pointed2, ChainRec);
var traverseReadonlyNonEmptyArrayWithIndex3 = (f) => flow(traverseReadonlyNonEmptyArrayWithIndex2(f), map(traverseReadonlyNonEmptyArrayWithIndex(SK)));
var traverseReadonlyArrayWithIndex = (f) => {
  const g = traverseReadonlyNonEmptyArrayWithIndex3(f);
  return (as3) => isNonEmpty(as3) ? g(as3) : ApT;
};
var chain = flatMap2;
var chainFirst = tap2;

export {
  some3 as some,
  fromPredicate2 as fromPredicate,
  fromOption,
  fromEither3 as fromEither,
  fromIO,
  fromIOEither,
  match2 as match,
  matchW,
  matchE2 as matchE,
  fold,
  matchEW,
  getOrElse2 as getOrElse,
  getOrElseW,
  toUndefined2 as toUndefined,
  toNullable2 as toNullable,
  fromNullable2 as fromNullable,
  fromNullableK2 as fromNullableK,
  chainNullableK2 as chainNullableK,
  fromOptionK2 as fromOptionK,
  map3 as map,
  ap2 as ap,
  of2 as of,
  flatMap2 as flatMap,
  flatten,
  alt2 as alt,
  altW,
  zero2 as zero,
  throwError,
  none,
  compact2 as compact,
  separate2 as separate,
  filter2 as filter,
  filterMap2 as filterMap,
  partition2 as partition,
  partitionMap2 as partitionMap,
  URI,
  Functor3 as Functor,
  as2 as as,
  asUnit2 as asUnit,
  flap2 as flap,
  Pointed2 as Pointed,
  Apply2 as Apply,
  apFirst2 as apFirst,
  apSecond2 as apSecond,
  Applicative,
  Chain2 as Chain,
  chainRec,
  ChainRec,
  FromEither,
  FromIO,
  tap2 as tap,
  tapEither2 as tapEither,
  tapIO2 as tapIO,
  Alt,
  Zero,
  guard2 as guard,
  Alternative,
  Monad2 as Monad,
  MonadIO,
  MonadThrow,
  Compactable2 as Compactable,
  Filterable2 as Filterable,
  flatMapIO2 as flatMapIO,
  flatMapOption,
  flatMapEither2 as flatMapEither,
  flatMapNullable,
  fromIOK2 as fromIOK,
  chainIOK,
  chainFirstIOK,
  fromEitherK2 as fromEitherK,
  chainEitherK,
  chainFirstEitherK,
  chainOptionK,
  Do,
  bindTo2 as bindTo,
  let_2 as let_,
  bind2 as bind,
  apS2 as apS,
  ApT,
  do_2 as do_,
  traverseReadonlyNonEmptyArrayWithIndex3 as traverseReadonlyNonEmptyArrayWithIndex,
  traverseReadonlyArrayWithIndex,
  chain,
  chainFirst,
  IOOption_exports
};
