"use strict";Object.defineProperty(exports, "__esModule", {value: true});

var _chunk7K74W2G3js = require('./chunk-7K74W2G3.js');



var _chunkSQA7G4TEjs = require('./chunk-SQA7G4TE.js');


var _chunk6C3VEZWHjs = require('./chunk-6C3VEZWH.js');

// src/ReadonlyTuple.ts
var ReadonlyTuple_exports = {};
_chunk6C3VEZWHjs.__export.call(void 0, ReadonlyTuple_exports, {
  Bifunctor: () => Bifunctor,
  Comonad: () => Comonad,
  Foldable: () => Foldable,
  Functor: () => Functor,
  Semigroupoid: () => Semigroupoid,
  Traversable: () => Traversable,
  URI: () => URI,
  bimap: () => bimap,
  compose: () => compose,
  duplicate: () => duplicate,
  extend: () => extend,
  extract: () => extract,
  flap: () => flap2,
  foldMap: () => foldMap,
  fst: () => fst,
  getApplicative: () => getApplicative,
  getApply: () => getApply,
  getChain: () => getChain,
  getChainRec: () => getChainRec,
  getMonad: () => getMonad,
  map: () => map,
  mapFst: () => mapFst,
  mapLeft: () => mapLeft,
  mapSnd: () => mapSnd,
  readonlyTuple: () => readonlyTuple,
  reduce: () => reduce,
  reduceRight: () => reduceRight,
  sequence: () => sequence,
  snd: () => snd,
  swap: () => swap,
  traverse: () => traverse
});
function fst(ea) {
  return ea[0];
}
function snd(ea) {
  return ea[1];
}
var swap = (ea) => [snd(ea), fst(ea)];
function getApply(S) {
  return {
    URI,
    _E: void 0,
    map: _map,
    ap: (fab, fa) => [fst(fab)(fst(fa)), S.concat(snd(fab), snd(fa))]
  };
}
var of = (M) => (a) => {
  return [a, M.empty];
};
function getApplicative(M) {
  const A = getApply(M);
  return {
    URI,
    _E: void 0,
    map: _map,
    ap: A.ap,
    of: of(M)
  };
}
function getChain(S) {
  const A = getApply(S);
  return {
    URI,
    _E: void 0,
    map: _map,
    ap: A.ap,
    chain: (ma, f) => {
      const [b, s] = f(fst(ma));
      return [b, S.concat(snd(ma), s)];
    }
  };
}
function getMonad(M) {
  const C = getChain(M);
  return {
    URI,
    _E: void 0,
    map: _map,
    ap: C.ap,
    chain: C.chain,
    of: of(M)
  };
}
function getChainRec(M) {
  const chainRec = (a, f) => {
    let result = f(a);
    let acc = M.empty;
    let s = fst(result);
    while (s._tag === "Left") {
      acc = M.concat(acc, snd(result));
      result = f(s.left);
      s = fst(result);
    }
    return [s.right, M.concat(acc, snd(result))];
  };
  const C = getChain(M);
  return {
    URI,
    _E: void 0,
    map: _map,
    ap: C.ap,
    chain: C.chain,
    chainRec
  };
}
var _compose = (bc, ab) => _chunkSQA7G4TEjs.pipe.call(void 0, bc, compose(ab));
var _map = (fa, f) => _chunkSQA7G4TEjs.pipe.call(void 0, fa, mapFst(f));
var _bimap = (fa, f, g) => _chunkSQA7G4TEjs.pipe.call(void 0, fa, bimap(f, g));
var _mapLeft = (fa, f) => _chunkSQA7G4TEjs.pipe.call(void 0, fa, mapSnd(f));
var _extend = (wa, f) => _chunkSQA7G4TEjs.pipe.call(void 0, wa, extend(f));
var _reduce = (fa, b, f) => _chunkSQA7G4TEjs.pipe.call(void 0, fa, reduce(b, f));
var _foldMap = (M) => {
  const foldMapM = foldMap(M);
  return (fa, f) => _chunkSQA7G4TEjs.pipe.call(void 0, fa, foldMapM(f));
};
var _reduceRight = (fa, b, f) => _chunkSQA7G4TEjs.pipe.call(void 0, fa, reduceRight(b, f));
var _traverse = (F) => {
  const traverseF = traverse(F);
  return (ta, f) => _chunkSQA7G4TEjs.pipe.call(void 0, ta, traverseF(f));
};
var bimap = (f, g) => (fa) => [g(fst(fa)), f(snd(fa))];
var mapFst = (f) => (fa) => [
  f(fst(fa)),
  snd(fa)
];
var mapSnd = (f) => (fa) => [
  fst(fa),
  f(snd(fa))
];
var compose = (ab) => (bc) => [
  fst(bc),
  snd(ab)
];
var extend = (f) => (wa) => [
  f(wa),
  snd(wa)
];
var extract = fst;
var duplicate = /* @__PURE__ */ extend(_chunkSQA7G4TEjs.identity);
var reduce = (b, f) => (fa) => f(b, fst(fa));
var foldMap = () => {
  return (f) => (fa) => f(fst(fa));
};
var reduceRight = (b, f) => (fa) => f(fst(fa), b);
var traverse = (F) => {
  return (f) => (ta) => F.map(f(fst(ta)), (b) => [b, snd(ta)]);
};
var sequence = (F) => (fas) => {
  return F.map(fst(fas), (a) => [a, snd(fas)]);
};
var URI = "ReadonlyTuple";
var Functor = {
  URI,
  map: _map
};
var flap2 = /* @__PURE__ */ _chunk7K74W2G3js.flap.call(void 0, Functor);
var map = mapFst;
var mapLeft = mapSnd;
var Bifunctor = {
  URI,
  bimap: _bimap,
  mapLeft: _mapLeft
};
var Semigroupoid = {
  URI,
  compose: _compose
};
var Comonad = {
  URI,
  map: _map,
  extend: _extend,
  extract
};
var Foldable = {
  URI,
  reduce: _reduce,
  foldMap: _foldMap,
  reduceRight: _reduceRight
};
var Traversable = {
  URI,
  map: _map,
  reduce: _reduce,
  foldMap: _foldMap,
  reduceRight: _reduceRight,
  traverse: _traverse,
  sequence
};
var readonlyTuple = {
  URI,
  compose: _compose,
  map: _map,
  bimap: _bimap,
  mapLeft: _mapLeft,
  extract,
  extend: _extend,
  reduce: _reduce,
  foldMap: _foldMap,
  reduceRight: _reduceRight,
  traverse: _traverse,
  sequence
};


































exports.fst = fst; exports.snd = snd; exports.swap = swap; exports.getApply = getApply; exports.getApplicative = getApplicative; exports.getChain = getChain; exports.getMonad = getMonad; exports.getChainRec = getChainRec; exports.bimap = bimap; exports.mapFst = mapFst; exports.mapSnd = mapSnd; exports.compose = compose; exports.extend = extend; exports.extract = extract; exports.duplicate = duplicate; exports.reduce = reduce; exports.foldMap = foldMap; exports.reduceRight = reduceRight; exports.traverse = traverse; exports.sequence = sequence; exports.URI = URI; exports.Functor = Functor; exports.flap = flap2; exports.map = map; exports.mapLeft = mapLeft; exports.Bifunctor = Bifunctor; exports.Semigroupoid = Semigroupoid; exports.Comonad = Comonad; exports.Foldable = Foldable; exports.Traversable = Traversable; exports.readonlyTuple = readonlyTuple; exports.ReadonlyTuple_exports = ReadonlyTuple_exports;
