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




var _chunkYUZQB73Kjs = require('./chunk-YUZQB73K.js');




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


var _chunkTGVEPLW2js = require('./chunk-TGVEPLW2.js');




var _chunkQ2LZCTWPjs = require('./chunk-Q2LZCTWP.js');



var _chunkEBISTSVAjs = require('./chunk-EBISTSVA.js');


var _chunkOTKMOSH2js = require('./chunk-OTKMOSH2.js');




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


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

// src/Tree.ts
var Tree_exports = {};
_chunk6C3VEZWHjs.__export.call(void 0, Tree_exports, {
  Applicative: () => Applicative,
  Apply: () => Apply,
  Chain: () => Chain,
  Comonad: () => Comonad,
  Do: () => Do,
  Foldable: () => Foldable,
  Functor: () => Functor,
  Monad: () => Monad,
  Pointed: () => Pointed,
  Traversable: () => Traversable,
  URI: () => URI,
  ap: () => ap,
  apFirst: () => apFirst2,
  apS: () => apS2,
  apSecond: () => apSecond2,
  bind: () => bind2,
  bindTo: () => bindTo2,
  chain: () => chain,
  chainFirst: () => chainFirst2,
  drawForest: () => drawForest,
  drawTree: () => drawTree,
  duplicate: () => duplicate,
  elem: () => elem,
  exists: () => exists,
  extend: () => extend,
  extract: () => extract,
  flap: () => flap2,
  flatMap: () => flatMap,
  flatten: () => flatten,
  fold: () => fold,
  foldMap: () => foldMap,
  getEq: () => getEq2,
  getShow: () => getShow,
  let: () => let_2,
  make: () => make,
  map: () => map,
  of: () => of,
  reduce: () => reduce,
  reduceRight: () => reduceRight,
  sequence: () => sequence,
  traverse: () => traverse2,
  tree: () => tree,
  unfoldForest: () => unfoldForest,
  unfoldForestM: () => unfoldForestM,
  unfoldTree: () => unfoldTree,
  unfoldTreeM: () => unfoldTreeM
});
function make(value, forest = []) {
  return {
    value,
    forest
  };
}
function getShow(S) {
  const show = (t) => {
    return _chunkYUZQB73Kjs.isEmpty.call(void 0, t.forest) ? `make(${S.show(t.value)})` : `make(${S.show(t.value)}, [${t.forest.map(show).join(", ")}])`;
  };
  return {
    show
  };
}
function getEq2(E) {
  let SA;
  const R = _chunkTGVEPLW2js.fromEquals.call(void 0, (x, y) => E.equals(x.value, y.value) && SA.equals(x.forest, y.forest));
  SA = _chunkYUZQB73Kjs.getEq.call(void 0, R);
  return R;
}
var draw = (indentation, forest) => {
  let r = "";
  const len = forest.length;
  let tree2;
  for (let i = 0; i < len; i++) {
    tree2 = forest[i];
    const isLast = i === len - 1;
    r += indentation + (isLast ? "\u2514" : "\u251C") + "\u2500 " + tree2.value;
    r += draw(indentation + (len > 1 && !isLast ? "\u2502  " : "   "), tree2.forest);
  }
  return r;
};
function drawForest(forest) {
  return draw("\n", forest);
}
function drawTree(tree2) {
  return tree2.value + drawForest(tree2.forest);
}
function unfoldTree(b, f) {
  const [a, bs] = f(b);
  return { value: a, forest: unfoldForest(bs, f) };
}
function unfoldForest(bs, f) {
  return bs.map((b) => unfoldTree(b, f));
}
function unfoldTreeM(M) {
  const unfoldForestMM = unfoldForestM(M);
  return (b, f) => M.chain(f(b), ([a, bs]) => M.map(unfoldForestMM(bs, f), (ts) => ({ value: a, forest: ts })));
}
function unfoldForestM(M) {
  const traverseM = _chunkYUZQB73Kjs.traverse.call(void 0, M);
  return (bs, f) => _chunkSQA7G4TEjs.pipe.call(void 0, 
    bs,
    traverseM((b) => unfoldTreeM(M)(b, f))
  );
}
function fold(f) {
  const go = (tree2) => f(tree2.value, tree2.forest.map(go));
  return go;
}
var _map = (fa, f) => _chunkSQA7G4TEjs.pipe.call(void 0, fa, map(f));
var _ap = (fab, fa) => flatMap(fab, (f) => _chunkSQA7G4TEjs.pipe.call(void 0, fa, map(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 _extend = (wa, f) => _chunkSQA7G4TEjs.pipe.call(void 0, wa, extend(f));
var _traverse = (F) => {
  const traverseF = traverse2(F);
  return (ta, f) => _chunkSQA7G4TEjs.pipe.call(void 0, ta, traverseF(f));
};
var ap = (fa) => (fab) => _ap(fab, fa);
var flatMap = /* @__PURE__ */ _chunkSQA7G4TEjs.dual.call(void 0, 2, (ma, f) => {
  const { value, forest } = f(ma.value);
  const concat = _chunkYUZQB73Kjs.getMonoid.call(void 0, ).concat;
  return {
    value,
    forest: concat(forest, ma.forest.map(flatMap(f)))
  };
});
var extend = (f) => (wa) => ({
  value: f(wa),
  forest: wa.forest.map(extend(f))
});
var duplicate = /* @__PURE__ */ extend(_chunkSQA7G4TEjs.identity);
var flatten = /* @__PURE__ */ flatMap(_chunkSQA7G4TEjs.identity);
var map = (f) => (fa) => ({
  value: f(fa.value),
  forest: fa.forest.map(map(f))
});
var reduce = (b, f) => (fa) => {
  let r = f(b, fa.value);
  const len = fa.forest.length;
  for (let i = 0; i < len; i++) {
    r = _chunkSQA7G4TEjs.pipe.call(void 0, fa.forest[i], reduce(r, f));
  }
  return r;
};
var foldMap = (M) => (f) => reduce(M.empty, (acc, a) => M.concat(acc, f(a)));
var reduceRight = (b, f) => (fa) => {
  let r = b;
  const len = fa.forest.length;
  for (let i = len - 1; i >= 0; i--) {
    r = _chunkSQA7G4TEjs.pipe.call(void 0, fa.forest[i], reduceRight(r, f));
  }
  return f(fa.value, r);
};
var extract = (wa) => wa.value;
var traverse2 = (F) => {
  const traverseF = _chunkYUZQB73Kjs.traverse.call(void 0, F);
  const out = (f) => (ta) => F.ap(
    F.map(f(ta.value), (value) => (forest) => ({
      value,
      forest
    })),
    _chunkSQA7G4TEjs.pipe.call(void 0, ta.forest, traverseF(out(f)))
  );
  return out;
};
var sequence = (F) => traverse2(F)(_chunkSQA7G4TEjs.identity);
var of = (a) => make(a);
var URI = "Tree";
var Functor = {
  URI,
  map: _map
};
var flap2 = /* @__PURE__ */ _chunk7K74W2G3js.flap.call(void 0, Functor);
var Pointed = {
  URI,
  of
};
var Apply = {
  URI,
  map: _map,
  ap: _ap
};
var apFirst2 = /* @__PURE__ */ _chunkQ2LZCTWPjs.apFirst.call(void 0, Apply);
var apSecond2 = /* @__PURE__ */ _chunkQ2LZCTWPjs.apSecond.call(void 0, Apply);
var Applicative = {
  URI,
  map: _map,
  ap: _ap,
  of
};
var Chain = {
  URI,
  map: _map,
  ap: _ap,
  chain: flatMap
};
var Monad = {
  URI,
  map: _map,
  ap: _ap,
  of,
  chain: flatMap
};
var chainFirst2 = /* @__PURE__ */ _chunkEBISTSVAjs.chainFirst.call(void 0, Chain);
var Foldable = {
  URI,
  reduce: _reduce,
  foldMap: _foldMap,
  reduceRight: _reduceRight
};
var Traversable = {
  URI,
  map: _map,
  reduce: _reduce,
  foldMap: _foldMap,
  reduceRight: _reduceRight,
  traverse: _traverse,
  sequence
};
var Comonad = {
  URI,
  map: _map,
  extend: _extend,
  extract
};
var Do = /* @__PURE__ */ of(_chunkOTKMOSH2js.emptyRecord);
var bindTo2 = /* @__PURE__ */ _chunk7K74W2G3js.bindTo.call(void 0, Functor);
var let_2 = /* @__PURE__ */ _chunk7K74W2G3js.let_.call(void 0, Functor);
var bind2 = /* @__PURE__ */ _chunkEBISTSVAjs.bind.call(void 0, Chain);
var apS2 = /* @__PURE__ */ _chunkQ2LZCTWPjs.apS.call(void 0, Apply);
function elem(E) {
  const go = (a, fa) => E.equals(a, fa.value) || fa.forest.some((tree2) => go(a, tree2));
  return go;
}
var exists = (predicate) => (ma) => predicate(ma.value) || ma.forest.some(exists(predicate));
var chain = flatMap;
var tree = {
  URI,
  map: _map,
  of,
  ap: _ap,
  chain: flatMap,
  reduce: _reduce,
  foldMap: _foldMap,
  reduceRight: _reduceRight,
  traverse: _traverse,
  sequence,
  extract,
  extend: _extend
};

















































exports.make = make; exports.getShow = getShow; exports.getEq = getEq2; exports.drawForest = drawForest; exports.drawTree = drawTree; exports.unfoldTree = unfoldTree; exports.unfoldForest = unfoldForest; exports.unfoldTreeM = unfoldTreeM; exports.unfoldForestM = unfoldForestM; exports.fold = fold; exports.ap = ap; exports.flatMap = flatMap; exports.extend = extend; exports.duplicate = duplicate; exports.flatten = flatten; exports.map = map; exports.reduce = reduce; exports.foldMap = foldMap; exports.reduceRight = reduceRight; exports.extract = extract; exports.traverse = traverse2; exports.sequence = sequence; exports.of = of; exports.URI = URI; exports.Functor = Functor; exports.flap = flap2; exports.Pointed = Pointed; exports.Apply = Apply; exports.apFirst = apFirst2; exports.apSecond = apSecond2; exports.Applicative = Applicative; exports.Chain = Chain; exports.Monad = Monad; exports.chainFirst = chainFirst2; exports.Foldable = Foldable; exports.Traversable = Traversable; exports.Comonad = Comonad; exports.Do = Do; exports.bindTo = bindTo2; exports.let_ = let_2; exports.bind = bind2; exports.apS = apS2; exports.elem = elem; exports.exists = exists; exports.chain = chain; exports.tree = tree; exports.Tree_exports = Tree_exports;
