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



















var _chunkFWQMQAFBjs = require('./chunk-FWQMQAFB.js');


var _chunkS2Z5L3RBjs = require('./chunk-S2Z5L3RB.js');


var _chunkT4ZJ6CA2js = require('./chunk-T4ZJ6CA2.js');



var _chunkUNAIGMDHjs = require('./chunk-UNAIGMDH.js');


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






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


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


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

// src/Map.ts
var Map_exports = {};
_chunk6C3VEZWHjs.__export.call(void 0, Map_exports, {
  Compactable: () => Compactable,
  Filterable: () => Filterable,
  Functor: () => Functor,
  URI: () => URI,
  collect: () => collect,
  compact: () => compact,
  deleteAt: () => deleteAt,
  difference: () => difference2,
  elem: () => elem2,
  empty: () => empty,
  filter: () => filter,
  filterMap: () => filterMap,
  filterMapWithIndex: () => filterMapWithIndex,
  filterWithIndex: () => filterWithIndex,
  flap: () => flap2,
  foldMap: () => foldMap2,
  foldMapWithIndex: () => foldMapWithIndex2,
  fromFoldable: () => fromFoldable,
  getDifferenceMagma: () => getDifferenceMagma,
  getEq: () => getEq2,
  getFilterableWithIndex: () => getFilterableWithIndex,
  getFoldable: () => getFoldable2,
  getFoldableWithIndex: () => getFoldableWithIndex2,
  getIntersectionSemigroup: () => getIntersectionSemigroup,
  getMonoid: () => getMonoid,
  getShow: () => getShow2,
  getTraversableWithIndex: () => getTraversableWithIndex,
  getUnionMonoid: () => getUnionMonoid,
  getUnionSemigroup: () => getUnionSemigroup,
  getWitherable: () => getWitherable,
  insertAt: () => insertAt,
  intersection: () => intersection2,
  isEmpty: () => isEmpty2,
  isSubmap: () => isSubmap2,
  keys: () => keys,
  lookup: () => lookup2,
  lookupWithKey: () => lookupWithKey,
  map: () => map2,
  mapWithIndex: () => mapWithIndex,
  map_: () => map_,
  member: () => member2,
  modifyAt: () => modifyAt,
  partition: () => partition,
  partitionMap: () => partitionMap,
  partitionMapWithIndex: () => partitionMapWithIndex,
  partitionWithIndex: () => partitionWithIndex,
  pop: () => pop,
  reduce: () => reduce2,
  reduceRight: () => reduceRight2,
  reduceRightWithIndex: () => reduceRightWithIndex2,
  reduceWithIndex: () => reduceWithIndex2,
  separate: () => separate,
  singleton: () => singleton,
  size: () => size2,
  toArray: () => toArray,
  toUnfoldable: () => toUnfoldable,
  union: () => union2,
  updateAt: () => updateAt,
  upsertAt: () => upsertAt,
  values: () => values
});
var getShow2 = _chunkFWQMQAFBjs.getShow;
var size2 = _chunkFWQMQAFBjs.size;
var isEmpty2 = _chunkFWQMQAFBjs.isEmpty;
var member2 = _chunkFWQMQAFBjs.member;
var elem2 = _chunkFWQMQAFBjs.elem;
var keys = (O) => (m) => Array.from(m.keys()).sort(O.compare);
var values = (O) => (m) => Array.from(m.values()).sort(O.compare);
function collect(O) {
  const keysO = keys(O);
  return (f) => (m) => {
    const out = [];
    const ks = keysO(m);
    for (const key of ks) {
      out.push(f(key, m.get(key)));
    }
    return out;
  };
}
function toArray(O) {
  return collect(O)((k, a) => [k, a]);
}
function toUnfoldable(ord, U) {
  const toArrayO = toArray(ord);
  return (d) => {
    const kas = toArrayO(d);
    const len = kas.length;
    return U.unfold(0, (b) => b < len ? _chunkOTKMOSH2js.some.call(void 0, [kas[b], b + 1]) : _chunkOTKMOSH2js.none);
  };
}
var upsertAt = (E) => {
  const lookupWithKeyE = lookupWithKey(E);
  return (k, a) => {
    const lookupWithKeyEk = lookupWithKeyE(k);
    return (m) => {
      const found = lookupWithKeyEk(m);
      if (_chunkOTKMOSH2js.isNone.call(void 0, found)) {
        const out = new Map(m);
        out.set(k, a);
        return out;
      } else if (found.value[1] !== a) {
        const out = new Map(m);
        out.set(found.value[0], a);
        return out;
      }
      return m;
    };
  };
};
var deleteAt = (E) => {
  const lookupWithKeyE = lookupWithKey(E);
  return (k) => (m) => {
    const found = lookupWithKeyE(k, m);
    if (_chunkOTKMOSH2js.isSome.call(void 0, found)) {
      const r = new Map(m);
      r.delete(found.value[0]);
      return r;
    }
    return m;
  };
};
var updateAt = (E) => {
  const modifyAtE = modifyAt(E);
  return (k, a) => modifyAtE(k, () => a);
};
var modifyAt = (E) => {
  const lookupWithKeyE = lookupWithKey(E);
  return (k, f) => (m) => {
    const found = lookupWithKeyE(k, m);
    if (_chunkOTKMOSH2js.isNone.call(void 0, found)) {
      return _chunkOTKMOSH2js.none;
    }
    const r = new Map(m);
    r.set(found.value[0], f(found.value[1]));
    return _chunkOTKMOSH2js.some.call(void 0, r);
  };
};
function pop(E) {
  const lookupE = lookup2(E);
  const deleteAtE = deleteAt(E);
  return (k) => {
    const deleteAtEk = deleteAtE(k);
    return (m) => _chunkSQA7G4TEjs.pipe.call(void 0, 
      lookupE(k, m),
      _chunkS2Z5L3RBjs.map2.call(void 0, (a) => [a, deleteAtEk(m)])
    );
  };
}
function lookupWithKey(E) {
  return (k, m) => {
    if (m === void 0) {
      const lookupWithKeyE = lookupWithKey(E);
      return (m2) => lookupWithKeyE(k, m2);
    }
    const entries = m.entries();
    let e;
    while (!(e = entries.next()).done) {
      const [ka, a] = e.value;
      if (E.equals(ka, k)) {
        return _chunkOTKMOSH2js.some.call(void 0, [ka, a]);
      }
    }
    return _chunkOTKMOSH2js.none;
  };
}
var lookup2 = _chunkFWQMQAFBjs.lookup;
var isSubmap2 = _chunkFWQMQAFBjs.isSubmap;
var getEq2 = _chunkFWQMQAFBjs.getEq;
function getMonoid(SK, SA) {
  const lookupWithKeyS = lookupWithKey(SK);
  return {
    concat: (mx, my) => {
      if (isEmpty2(mx)) {
        return my;
      }
      if (isEmpty2(my)) {
        return mx;
      }
      const r = new Map(mx);
      const entries = my.entries();
      let e;
      while (!(e = entries.next()).done) {
        const [k, a] = e.value;
        const mxOptA = lookupWithKeyS(k, mx);
        if (_chunkOTKMOSH2js.isSome.call(void 0, mxOptA)) {
          r.set(mxOptA.value[0], SA.concat(mxOptA.value[1], a));
        } else {
          r.set(k, a);
        }
      }
      return r;
    },
    empty: /* @__PURE__ */ new Map()
  };
}
var singleton = (k, a) => /* @__PURE__ */ new Map([[k, a]]);
function fromFoldable(E, M, F) {
  return (fka) => {
    const lookupWithKeyE = lookupWithKey(E);
    return F.reduce(fka, /* @__PURE__ */ new Map(), (b, [k, a]) => {
      const bOpt = lookupWithKeyE(k, b);
      if (_chunkOTKMOSH2js.isSome.call(void 0, bOpt)) {
        b.set(bOpt.value[0], M.concat(bOpt.value[1], a));
      } else {
        b.set(k, a);
      }
      return b;
    });
  };
}
var _mapWithIndex = (fa, f) => {
  const m = /* @__PURE__ */ new Map();
  const entries = fa.entries();
  let e;
  while (!(e = entries.next()).done) {
    const [key, a] = e.value;
    m.set(key, f(key, a));
  }
  return m;
};
var partitionMapWithIndex = (f) => (fa) => {
  const left = /* @__PURE__ */ new Map();
  const right = /* @__PURE__ */ new Map();
  const entries = fa.entries();
  let e;
  while (!(e = entries.next()).done) {
    const [k, a] = e.value;
    const ei = f(k, a);
    if (_chunkOTKMOSH2js.isLeft.call(void 0, ei)) {
      left.set(k, ei.left);
    } else {
      right.set(k, ei.right);
    }
  }
  return _chunkT4ZJ6CA2js.separated.call(void 0, left, right);
};
function partitionWithIndex(predicateWithIndex) {
  return (fa) => {
    const left = /* @__PURE__ */ new Map();
    const right = /* @__PURE__ */ new Map();
    const entries = fa.entries();
    let e;
    while (!(e = entries.next()).done) {
      const [k, a] = e.value;
      if (predicateWithIndex(k, a)) {
        right.set(k, a);
      } else {
        left.set(k, a);
      }
    }
    return _chunkT4ZJ6CA2js.separated.call(void 0, left, right);
  };
}
var filterMapWithIndex = (f) => (fa) => {
  const m = /* @__PURE__ */ new Map();
  const entries = fa.entries();
  let e;
  while (!(e = entries.next()).done) {
    const [k, a] = e.value;
    const o = f(k, a);
    if (_chunkOTKMOSH2js.isSome.call(void 0, o)) {
      m.set(k, o.value);
    }
  }
  return m;
};
function filterWithIndex(p) {
  return (m) => {
    const out = /* @__PURE__ */ new Map();
    const entries = m.entries();
    let e;
    while (!(e = entries.next()).done) {
      const [k, a] = e.value;
      if (p(k, a)) {
        out.set(k, a);
      }
    }
    return out;
  };
}
var _map = (fa, f) => _mapWithIndex(fa, (_, a) => f(a));
var _filter = (fa, p) => _filterWithIndex(fa, (_, a) => p(a));
var _filterMap = (fa, f) => _filterMapWithIndex(fa, (_, a) => f(a));
var _partition = (fa, predicate) => _partitionWithIndex(fa, (_, a) => predicate(a));
var _partitionMap = (fa, f) => _partitionMapWithIndex(fa, (_, a) => f(a));
var _filterWithIndex = (fa, p) => _chunkSQA7G4TEjs.pipe.call(void 0, fa, filterWithIndex(p));
var _filterMapWithIndex = (fa, f) => _chunkSQA7G4TEjs.pipe.call(void 0, fa, filterMapWithIndex(f));
var _partitionWithIndex = (fa, p) => _chunkSQA7G4TEjs.pipe.call(void 0, fa, partitionWithIndex(p));
var _partitionMapWithIndex = (fa, f) => _chunkSQA7G4TEjs.pipe.call(void 0, fa, partitionMapWithIndex(f));
var compact = (fa) => {
  const m = /* @__PURE__ */ new Map();
  const entries = fa.entries();
  let e;
  while (!(e = entries.next()).done) {
    const [k, oa] = e.value;
    if (_chunkOTKMOSH2js.isSome.call(void 0, oa)) {
      m.set(k, oa.value);
    }
  }
  return m;
};
var filter = (predicate) => (fa) => _filter(fa, predicate);
var filterMap = (f) => (fa) => _filterMap(fa, f);
var map2 = (f) => (fa) => _map(fa, f);
var mapWithIndex = (f) => (fa) => _mapWithIndex(fa, f);
var partition = (predicate) => (fa) => _partition(fa, predicate);
var partitionMap = (f) => (fa) => _partitionMap(fa, f);
var separate = (fa) => {
  const left = /* @__PURE__ */ new Map();
  const right = /* @__PURE__ */ new Map();
  const entries = fa.entries();
  let e;
  while (!(e = entries.next()).done) {
    const [k, ei] = e.value;
    if (_chunkOTKMOSH2js.isLeft.call(void 0, ei)) {
      left.set(k, ei.left);
    } else {
      right.set(k, ei.right);
    }
  }
  return _chunkT4ZJ6CA2js.separated.call(void 0, left, right);
};
var URI = "Map";
var getUnionSemigroup = (E, S) => {
  const unionES = union2(E, S);
  return {
    concat: (first, second) => unionES(second)(first)
  };
};
var getUnionMonoid = (E, S) => ({
  concat: getUnionSemigroup(E, S).concat,
  empty: /* @__PURE__ */ new Map()
});
var getIntersectionSemigroup = (E, S) => {
  const intersectionES = intersection2(E, S);
  return {
    concat: (first, second) => intersectionES(second)(first)
  };
};
var getDifferenceMagma = (E) => () => {
  const differenceE = difference2(E);
  return {
    concat: (first, second) => differenceE(second)(first)
  };
};
function getFilterableWithIndex() {
  return {
    URI,
    _E: void 0,
    map: _map,
    mapWithIndex: _mapWithIndex,
    compact,
    separate,
    filter: _filter,
    filterMap: _filterMap,
    partition: _partition,
    partitionMap: _partitionMap,
    partitionMapWithIndex: _partitionMapWithIndex,
    partitionWithIndex: _partitionWithIndex,
    filterMapWithIndex: _filterMapWithIndex,
    filterWithIndex: _filterWithIndex
  };
}
function getWitherable(O) {
  const TWI = getTraversableWithIndex(O);
  return {
    URI,
    _E: void 0,
    map: _map,
    compact,
    separate,
    filter: _filter,
    filterMap: _filterMap,
    partition: _partition,
    partitionMap: _partitionMap,
    reduce: TWI.reduce,
    foldMap: TWI.foldMap,
    reduceRight: TWI.reduceRight,
    traverse: TWI.traverse,
    sequence: TWI.sequence,
    mapWithIndex: _mapWithIndex,
    reduceWithIndex: TWI.reduceWithIndex,
    foldMapWithIndex: TWI.foldMapWithIndex,
    reduceRightWithIndex: TWI.reduceRightWithIndex,
    traverseWithIndex: TWI.traverseWithIndex,
    wilt: _chunkUNAIGMDHjs.wiltDefault.call(void 0, TWI, Compactable),
    wither: _chunkUNAIGMDHjs.witherDefault.call(void 0, TWI, Compactable)
  };
}
var reduce2 = _chunkFWQMQAFBjs.reduce;
var foldMap2 = _chunkFWQMQAFBjs.foldMap;
var reduceRight2 = _chunkFWQMQAFBjs.reduceRight;
var getFoldable2 = (O) => {
  return {
    ..._chunkFWQMQAFBjs.getFoldable.call(void 0, O),
    URI
  };
};
var reduceWithIndex2 = _chunkFWQMQAFBjs.reduceWithIndex;
var foldMapWithIndex2 = _chunkFWQMQAFBjs.foldMapWithIndex;
var reduceRightWithIndex2 = _chunkFWQMQAFBjs.reduceRightWithIndex;
var getFoldableWithIndex2 = (O) => {
  return {
    ..._chunkFWQMQAFBjs.getFoldableWithIndex.call(void 0, O),
    URI
  };
};
var getTraversableWithIndex = (O) => {
  const FWI = getFoldableWithIndex2(O);
  const keysO = keys(O);
  const traverseWithIndex = (F) => {
    return (ta, f) => {
      let fm = F.of(/* @__PURE__ */ new Map());
      const ks = keysO(ta);
      const len = ks.length;
      for (let i = 0; i < len; i++) {
        const key = ks[i];
        const a = ta.get(key);
        fm = F.ap(
          F.map(fm, (m) => (b) => m.set(key, b)),
          f(key, a)
        );
      }
      return fm;
    };
  };
  const traverse = (F) => {
    const traverseWithIndexF = traverseWithIndex(F);
    return (ta, f) => traverseWithIndexF(ta, (_, a) => f(a));
  };
  const sequence = (F) => {
    const traverseWithIndexF = traverseWithIndex(F);
    return (ta) => traverseWithIndexF(ta, (_, a) => a);
  };
  return {
    URI,
    _E: void 0,
    map: _map,
    mapWithIndex: _mapWithIndex,
    reduce: FWI.reduce,
    foldMap: FWI.foldMap,
    reduceRight: FWI.reduceRight,
    reduceWithIndex: FWI.reduceWithIndex,
    foldMapWithIndex: FWI.foldMapWithIndex,
    reduceRightWithIndex: FWI.reduceRightWithIndex,
    traverse,
    sequence,
    traverseWithIndex
  };
};
var Functor = {
  URI,
  map: _map
};
var flap2 = /* @__PURE__ */ _chunk7K74W2G3js.flap.call(void 0, Functor);
var Compactable = {
  URI,
  compact,
  separate
};
var Filterable = {
  URI,
  map: _map,
  compact,
  separate,
  filter: _filter,
  filterMap: _filterMap,
  partition: _partition,
  partitionMap: _partitionMap
};
var copy = (m) => new Map(m);
var union2 = (E, M) => {
  const unionEM = _chunkFWQMQAFBjs.union.call(void 0, E, M);
  return (second) => (first) => {
    if (isEmpty2(first)) {
      return copy(second);
    }
    if (isEmpty2(second)) {
      return copy(first);
    }
    return unionEM(second)(first);
  };
};
var intersection2 = (E, M) => {
  const intersectionEM = _chunkFWQMQAFBjs.intersection.call(void 0, E, M);
  return (second) => (first) => {
    if (isEmpty2(first) || isEmpty2(second)) {
      return /* @__PURE__ */ new Map();
    }
    return intersectionEM(second)(first);
  };
};
var difference2 = (E) => {
  const differenceE = _chunkFWQMQAFBjs.difference.call(void 0, E);
  return (second) => (first) => {
    if (isEmpty2(first)) {
      return copy(second);
    }
    if (isEmpty2(second)) {
      return copy(first);
    }
    return differenceE(second)(first);
  };
};
var empty = /* @__PURE__ */ new Map();
var insertAt = upsertAt;
var map_ = Filterable;































































exports.getShow = getShow2; exports.size = size2; exports.isEmpty = isEmpty2; exports.member = member2; exports.elem = elem2; exports.keys = keys; exports.values = values; exports.collect = collect; exports.toArray = toArray; exports.toUnfoldable = toUnfoldable; exports.upsertAt = upsertAt; exports.deleteAt = deleteAt; exports.updateAt = updateAt; exports.modifyAt = modifyAt; exports.pop = pop; exports.lookupWithKey = lookupWithKey; exports.lookup = lookup2; exports.isSubmap = isSubmap2; exports.getEq = getEq2; exports.getMonoid = getMonoid; exports.singleton = singleton; exports.fromFoldable = fromFoldable; exports.partitionMapWithIndex = partitionMapWithIndex; exports.partitionWithIndex = partitionWithIndex; exports.filterMapWithIndex = filterMapWithIndex; exports.filterWithIndex = filterWithIndex; exports.compact = compact; exports.filter = filter; exports.filterMap = filterMap; exports.map = map2; exports.mapWithIndex = mapWithIndex; exports.partition = partition; exports.partitionMap = partitionMap; exports.separate = separate; exports.URI = URI; exports.getUnionSemigroup = getUnionSemigroup; exports.getUnionMonoid = getUnionMonoid; exports.getIntersectionSemigroup = getIntersectionSemigroup; exports.getDifferenceMagma = getDifferenceMagma; exports.getFilterableWithIndex = getFilterableWithIndex; exports.getWitherable = getWitherable; exports.reduce = reduce2; exports.foldMap = foldMap2; exports.reduceRight = reduceRight2; exports.getFoldable = getFoldable2; exports.reduceWithIndex = reduceWithIndex2; exports.foldMapWithIndex = foldMapWithIndex2; exports.reduceRightWithIndex = reduceRightWithIndex2; exports.getFoldableWithIndex = getFoldableWithIndex2; exports.getTraversableWithIndex = getTraversableWithIndex; exports.Functor = Functor; exports.flap = flap2; exports.Compactable = Compactable; exports.Filterable = Filterable; exports.union = union2; exports.intersection = intersection2; exports.difference = difference2; exports.empty = empty; exports.insertAt = insertAt; exports.map_ = map_; exports.Map_exports = Map_exports;
