import {
  Apply2 as Apply,
  Functor2 as Functor,
  fromEither,
  fromNullable2 as fromNullable,
  fromPredicate2 as fromPredicate,
  match2 as match,
  none,
  some
} from "./chunk-3AL4EMTU.mjs";
import {
  map
} from "./chunk-WKK6AYQI.mjs";
import {
  ap
} from "./chunk-ZMCLCMOU.mjs";
import {
  constant,
  flow,
  pipe
} from "./chunk-ZI34HWXZ.mjs";
import {
  __export
} from "./chunk-QK4PKNB3.mjs";

// src/OptionT.ts
var OptionT_exports = {};
__export(OptionT_exports, {
  alt: () => alt,
  ap: () => ap2,
  chain: () => chain,
  chainNullableK: () => chainNullableK,
  chainOptionK: () => chainOptionK,
  flatMap: () => flatMap,
  fromEither: () => fromEither2,
  fromF: () => fromF,
  fromNullable: () => fromNullable2,
  fromNullableK: () => fromNullableK,
  fromOptionK: () => fromOptionK,
  fromPredicate: () => fromPredicate2,
  getOptionM: () => getOptionM,
  getOrElse: () => getOrElse,
  map: () => map2,
  match: () => match2,
  matchE: () => matchE,
  some: () => some2,
  zero: () => zero
});
function some2(F) {
  return flow(some, F.of);
}
function zero(F) {
  return constant(F.of(none));
}
function fromF(F) {
  return (ma) => F.map(ma, some);
}
function fromNullable2(F) {
  return flow(fromNullable, F.of);
}
function fromNullableK(F) {
  const fromNullableF = fromNullable2(F);
  return (f) => flow(f, fromNullableF);
}
function chainNullableK(M) {
  const chainM = chain(M);
  const fromNullableKM = fromNullableK(M);
  return (f) => chainM(fromNullableKM(f));
}
function fromOptionK(F) {
  return (f) => flow(f, F.of);
}
function chainOptionK(M) {
  const chainM = chain(M);
  const fromOptionKM = fromOptionK(M);
  return (f) => chainM(fromOptionKM(f));
}
function fromPredicate2(F) {
  return (predicate) => (a) => F.of(fromPredicate(predicate)(a));
}
function fromEither2(F) {
  return flow(fromEither, F.of);
}
function match2(F) {
  return (onNone, onSome) => (ma) => F.map(ma, match(onNone, onSome));
}
function matchE(M) {
  return (onNone, onSome) => (ma) => M.chain(ma, match(onNone, onSome));
}
function getOrElse(M) {
  return (onNone) => (fa) => M.chain(fa, match(onNone, M.of));
}
function map2(F) {
  return map(F, Functor);
}
function ap2(F) {
  return ap(F, Apply);
}
function chain(M) {
  const flatMapM = flatMap(M);
  return (f) => (ma) => flatMapM(ma, f);
}
function flatMap(M) {
  const zeroM = zero(M);
  return (ma, f) => M.chain(
    ma,
    match(() => zeroM(), f)
  );
}
function alt(M) {
  const _some = some2(M);
  return (second) => (first) => M.chain(first, match(second, _some));
}
function getOptionM(M) {
  const apM = ap2(M);
  const mapM = map2(M);
  const chainM = chain(M);
  const altM = alt(M);
  const foldM = matchE(M);
  const getOrElseM = getOrElse(M);
  const zeroM = zero(M);
  return {
    map: (fa, f) => pipe(fa, mapM(f)),
    ap: (fab, fa) => pipe(fab, apM(fa)),
    of: some2(M),
    chain: (ma, f) => pipe(ma, chainM(f)),
    alt: (fa, that) => pipe(fa, altM(that)),
    fold: (fa, onNone, onSome) => pipe(fa, foldM(onNone, onSome)),
    getOrElse: (fa, onNone) => pipe(fa, getOrElseM(onNone)),
    fromM: fromF(M),
    none: () => zeroM()
  };
}

export {
  some2 as some,
  zero,
  fromF,
  fromNullable2 as fromNullable,
  fromNullableK,
  chainNullableK,
  fromOptionK,
  chainOptionK,
  fromPredicate2 as fromPredicate,
  fromEither2 as fromEither,
  match2 as match,
  matchE,
  getOrElse,
  map2 as map,
  ap2 as ap,
  chain,
  flatMap,
  alt,
  getOptionM,
  OptionT_exports
};
