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









var _chunkCMJY6VYSjs = require('./chunk-CMJY6VYS.js');


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


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


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

// src/Set.ts
var Set_exports = {};
_chunk6C3VEZWHjs.__export.call(void 0, Set_exports, {
  chain: () => chain,
  compact: () => compact,
  difference: () => difference,
  elem: () => elem2,
  empty: () => empty,
  every: () => every2,
  filter: () => filter,
  filterMap: () => filterMap,
  foldMap: () => foldMap2,
  fromArray: () => fromArray,
  getDifferenceMagma: () => getDifferenceMagma,
  getEq: () => getEq2,
  getIntersectionSemigroup: () => getIntersectionSemigroup,
  getShow: () => getShow2,
  getUnionMonoid: () => getUnionMonoid,
  getUnionSemigroup: () => getUnionSemigroup,
  insert: () => insert,
  intersection: () => intersection,
  isEmpty: () => isEmpty,
  isSubset: () => isSubset2,
  map: () => map,
  partition: () => partition,
  partitionMap: () => partitionMap,
  reduce: () => reduce2,
  reduceRight: () => reduceRight2,
  remove: () => remove,
  separate: () => separate,
  singleton: () => singleton,
  size: () => size,
  some: () => some2,
  subset: () => subset,
  toArray: () => toArray,
  toggle: () => toggle,
  union: () => union
});
var getShow2 = _chunkCMJY6VYSjs.getShow;
var getEq2 = _chunkCMJY6VYSjs.getEq;
function map(E) {
  const elemE = elem2(E);
  return (f) => (set) => {
    const r = /* @__PURE__ */ new Set();
    set.forEach((e) => {
      const v = f(e);
      if (!elemE(v, r)) {
        r.add(v);
      }
    });
    return r;
  };
}
function chain(E) {
  const elemE = elem2(E);
  return (f) => (set) => {
    const r = /* @__PURE__ */ new Set();
    set.forEach((e) => {
      f(e).forEach((e2) => {
        if (!elemE(e2, r)) {
          r.add(e2);
        }
      });
    });
    return r;
  };
}
function filter(predicate) {
  return (set) => {
    const values = set.values();
    let e;
    const r = /* @__PURE__ */ new Set();
    while (!(e = values.next()).done) {
      const a = e.value;
      if (predicate(a)) {
        r.add(a);
      }
    }
    return r;
  };
}
function partition(predicate) {
  return (set) => {
    const values = set.values();
    let e;
    const right = /* @__PURE__ */ new Set();
    const left = /* @__PURE__ */ new Set();
    while (!(e = values.next()).done) {
      const a = e.value;
      if (predicate(a)) {
        right.add(a);
      } else {
        left.add(a);
      }
    }
    return _chunkT4ZJ6CA2js.separated.call(void 0, left, right);
  };
}
function union(E) {
  const elemE = elem2(E);
  return (me, that) => {
    if (that === void 0) {
      const unionE = union(E);
      return (that2) => unionE(me, that2);
    }
    if (isEmpty(me)) {
      return that;
    }
    if (isEmpty(that)) {
      return me;
    }
    const r = new Set(me);
    that.forEach((e) => {
      if (!elemE(e, r)) {
        r.add(e);
      }
    });
    return r;
  };
}
function intersection(E) {
  const elemE = elem2(E);
  return (me, that) => {
    if (that === void 0) {
      const intersectionE = intersection(E);
      return (that2) => intersectionE(that2, me);
    }
    if (isEmpty(me) || isEmpty(that)) {
      return /* @__PURE__ */ new Set();
    }
    const r = /* @__PURE__ */ new Set();
    me.forEach((e) => {
      if (elemE(e, that)) {
        r.add(e);
      }
    });
    return r;
  };
}
function partitionMap(EB, EC) {
  return (f) => (set) => {
    const values = set.values();
    let e;
    const left = /* @__PURE__ */ new Set();
    const right = /* @__PURE__ */ new Set();
    const hasB = elem2(EB);
    const hasC = elem2(EC);
    while (!(e = values.next()).done) {
      const v = f(e.value);
      switch (v._tag) {
        case "Left":
          if (!hasB(v.left, left)) {
            left.add(v.left);
          }
          break;
        case "Right":
          if (!hasC(v.right, right)) {
            right.add(v.right);
          }
          break;
      }
    }
    return _chunkT4ZJ6CA2js.separated.call(void 0, left, right);
  };
}
function difference(E) {
  const elemE = elem2(E);
  return (me, that) => {
    if (that === void 0) {
      const differenceE = difference(E);
      return (that2) => differenceE(that2, me);
    }
    return filter((a) => !elemE(a, that))(me);
  };
}
var getUnionSemigroup = (E) => ({
  concat: union(E)
});
var getUnionMonoid = (E) => ({
  concat: getUnionSemigroup(E).concat,
  empty: /* @__PURE__ */ new Set()
});
var getIntersectionSemigroup = (E) => ({
  concat: intersection(E)
});
var getDifferenceMagma = (E) => ({
  concat: difference(E)
});
var reduce2 = _chunkCMJY6VYSjs.reduce;
var foldMap2 = _chunkCMJY6VYSjs.foldMap;
var reduceRight2 = _chunkCMJY6VYSjs.reduceRight;
var singleton = (a) => /* @__PURE__ */ new Set([a]);
function insert(E) {
  const elemE = elem2(E);
  return (a) => (set) => {
    if (!elemE(a)(set)) {
      const r = new Set(set);
      r.add(a);
      return r;
    } else {
      return set;
    }
  };
}
var remove = (E) => (a) => (set) => filter((ax) => !E.equals(a, ax))(set);
var toggle = (E) => {
  const elemE = elem2(E);
  const removeE = remove(E);
  const insertE = insert(E);
  return (a) => (set) => (elemE(a, set) ? removeE : insertE)(a)(set);
};
var fromArray = (E) => (as) => {
  const len = as.length;
  const out = /* @__PURE__ */ new Set();
  const has = elem2(E);
  for (let i = 0; i < len; i++) {
    const a = as[i];
    if (!has(a, out)) {
      out.add(a);
    }
  }
  return out;
};
var compact = (E) => filterMap(E)(_chunkSQA7G4TEjs.identity);
function separate(EE, EA) {
  return (fa) => {
    const elemEE = elem2(EE);
    const elemEA = elem2(EA);
    const left = /* @__PURE__ */ new Set();
    const right = /* @__PURE__ */ new Set();
    fa.forEach((e) => {
      switch (e._tag) {
        case "Left":
          if (!elemEE(e.left, left)) {
            left.add(e.left);
          }
          break;
        case "Right":
          if (!elemEA(e.right, right)) {
            right.add(e.right);
          }
          break;
      }
    });
    return _chunkT4ZJ6CA2js.separated.call(void 0, left, right);
  };
}
function filterMap(E) {
  const elemE = elem2(E);
  return (f) => (fa) => {
    const r = /* @__PURE__ */ new Set();
    fa.forEach((a) => {
      const ob = f(a);
      if (ob._tag === "Some" && !elemE(ob.value, r)) {
        r.add(ob.value);
      }
    });
    return r;
  };
}
var empty = /* @__PURE__ */ new Set();
var isEmpty = (set) => set.size === 0;
var size = (set) => set.size;
var some2 = _chunkCMJY6VYSjs.some;
var every2 = _chunkCMJY6VYSjs.every;
var isSubset2 = _chunkCMJY6VYSjs.isSubset;
var elem2 = _chunkCMJY6VYSjs.elem;
var toArray = (O) => (set) => {
  const out = [];
  set.forEach((e) => out.push(e));
  return out.sort(O.compare);
};
var subset = _chunkCMJY6VYSjs.isSubset;





































exports.getShow = getShow2; exports.getEq = getEq2; exports.map = map; exports.chain = chain; exports.filter = filter; exports.partition = partition; exports.union = union; exports.intersection = intersection; exports.partitionMap = partitionMap; exports.difference = difference; exports.getUnionSemigroup = getUnionSemigroup; exports.getUnionMonoid = getUnionMonoid; exports.getIntersectionSemigroup = getIntersectionSemigroup; exports.getDifferenceMagma = getDifferenceMagma; exports.reduce = reduce2; exports.foldMap = foldMap2; exports.reduceRight = reduceRight2; exports.singleton = singleton; exports.insert = insert; exports.remove = remove; exports.toggle = toggle; exports.fromArray = fromArray; exports.compact = compact; exports.separate = separate; exports.filterMap = filterMap; exports.empty = empty; exports.isEmpty = isEmpty; exports.size = size; exports.some = some2; exports.every = every2; exports.isSubset = isSubset2; exports.elem = elem2; exports.toArray = toArray; exports.subset = subset; exports.Set_exports = Set_exports;
