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

var _chunkH2RXSEUSjs = require('./chunk-H2RXSEUS.js');


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


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


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


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

// src/ReadonlySet.ts
var ReadonlySet_exports = {};
_chunk6C3VEZWHjs.__export.call(void 0, ReadonlySet_exports, {
  URI: () => URI,
  chain: () => chain,
  compact: () => compact,
  difference: () => difference,
  elem: () => elem,
  empty: () => empty,
  every: () => every,
  filter: () => filter,
  filterMap: () => filterMap,
  foldMap: () => foldMap,
  fromArray: () => fromArray,
  fromReadonlyArray: () => fromReadonlyArray,
  fromSet: () => fromSet,
  getDifferenceMagma: () => getDifferenceMagma,
  getEq: () => getEq,
  getIntersectionSemigroup: () => getIntersectionSemigroup,
  getShow: () => getShow,
  getUnionMonoid: () => getUnionMonoid,
  getUnionSemigroup: () => getUnionSemigroup,
  insert: () => insert,
  intersection: () => intersection,
  isEmpty: () => isEmpty,
  isSubset: () => isSubset,
  map: () => map,
  partition: () => partition,
  partitionMap: () => partitionMap,
  reduce: () => reduce,
  reduceRight: () => reduceRight,
  remove: () => remove,
  separate: () => separate,
  singleton: () => singleton,
  size: () => size,
  some: () => some,
  toReadonlyArray: () => toReadonlyArray,
  toSet: () => toSet,
  toggle: () => toggle,
  union: () => union
});
var fromSet = (s) => new Set(s);
var singleton = (a) => /* @__PURE__ */ new Set([a]);
var fromReadonlyArray = (E) => (as) => {
  const len = as.length;
  const out = /* @__PURE__ */ new Set();
  const has = elem(E);
  for (let i = 0; i < len; i++) {
    const a = as[i];
    if (!has(a, out)) {
      out.add(a);
    }
  }
  return out;
};
function toSet(s) {
  return new Set(s);
}
function map(E) {
  const elemE = elem(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 = elem(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 = elem(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 = elem(E);
  return (me, that) => {
    if (that === void 0) {
      const intersectionE = intersection(E);
      return (that2) => intersectionE(that2, me);
    }
    if (isEmpty(me) || isEmpty(that)) {
      return empty;
    }
    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 = elem(EB);
    const hasC = elem(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 = elem(E);
  return (me, that) => {
    if (that === void 0) {
      const differenceE = difference(E);
      return (that2) => differenceE(that2, me);
    }
    return filter((a) => !elemE(a, that))(me);
  };
}
function reduce(O) {
  const toReadonlyArrayO = toReadonlyArray(O);
  return (b, f) => (fa) => toReadonlyArrayO(fa).reduce(f, b);
}
function foldMap(O, M) {
  const toReadonlyArrayO = toReadonlyArray(O);
  return (f) => (fa) => toReadonlyArrayO(fa).reduce((b, a) => M.concat(b, f(a)), M.empty);
}
var reduceRight = (O) => {
  const toReadonlyArrayO = toReadonlyArray(O);
  return (b, f) => (fa) => toReadonlyArrayO(fa).reduceRight((b2, a) => f(a, b2), b);
};
function insert(E) {
  const elemE = elem(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 = elem(E);
  const removeE = remove(E);
  const insertE = insert(E);
  return (a) => (set) => (elemE(a, set) ? removeE : insertE)(a)(set);
};
var compact = (E) => filterMap(E)(_chunkSQA7G4TEjs.identity);
function separate(EE, EA) {
  return (fa) => {
    const elemEE = elem(EE);
    const elemEA = elem(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 = elem(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 some = (predicate) => (set) => {
  const values = set.values();
  let e;
  let found = false;
  while (!found && !(e = values.next()).done) {
    found = predicate(e.value);
  }
  return found;
};
function every(predicate) {
  return _chunkH2RXSEUSjs.not.call(void 0, some(_chunkH2RXSEUSjs.not.call(void 0, predicate)));
}
function isSubset(E) {
  const elemE = elem(E);
  return (me, that) => {
    if (that === void 0) {
      const isSubsetE = isSubset(E);
      return (that2) => isSubsetE(that2, me);
    }
    return every((a) => elemE(a, that))(me);
  };
}
function elem(E) {
  return (a, set) => {
    if (set === void 0) {
      const elemE = elem(E);
      return (set2) => elemE(a, set2);
    }
    const values = set.values();
    let e;
    let found = false;
    while (!found && !(e = values.next()).done) {
      found = E.equals(a, e.value);
    }
    return found;
  };
}
var toReadonlyArray = (O) => (set) => {
  const out = [];
  set.forEach((e) => out.push(e));
  return out.sort(O.compare);
};
var URI = "ReadonlySet";
function getShow(S) {
  return {
    show: (s) => {
      const entries = [];
      s.forEach((a) => {
        entries.push(S.show(a));
      });
      return `new Set([${entries.sort().join(", ")}])`;
    }
  };
}
function getEq(E) {
  const subsetE = isSubset(E);
  return _chunkTGVEPLW2js.fromEquals.call(void 0, (x, y) => subsetE(x, y) && subsetE(y, x));
}
var getUnionSemigroup = (E) => ({
  concat: union(E)
});
var getUnionMonoid = (E) => ({
  concat: getUnionSemigroup(E).concat,
  empty
});
var getIntersectionSemigroup = (E) => ({
  concat: intersection(E)
});
var getDifferenceMagma = (E) => ({
  concat: difference(E)
});
var fromArray = fromReadonlyArray;








































exports.fromSet = fromSet; exports.singleton = singleton; exports.fromReadonlyArray = fromReadonlyArray; exports.toSet = toSet; 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.reduce = reduce; exports.foldMap = foldMap; exports.reduceRight = reduceRight; exports.insert = insert; exports.remove = remove; exports.toggle = toggle; exports.compact = compact; exports.separate = separate; exports.filterMap = filterMap; exports.empty = empty; exports.isEmpty = isEmpty; exports.size = size; exports.some = some; exports.every = every; exports.isSubset = isSubset; exports.elem = elem; exports.toReadonlyArray = toReadonlyArray; exports.URI = URI; exports.getShow = getShow; exports.getEq = getEq; exports.getUnionSemigroup = getUnionSemigroup; exports.getUnionMonoid = getUnionMonoid; exports.getIntersectionSemigroup = getIntersectionSemigroup; exports.getDifferenceMagma = getDifferenceMagma; exports.fromArray = fromArray; exports.ReadonlySet_exports = ReadonlySet_exports;
