import {
  eqStrict
} from "./chunk-YQKF55QL.mjs";
import {
  constTrue,
  constant,
  pipe
} from "./chunk-ZI34HWXZ.mjs";
import {
  __export
} from "./chunk-QK4PKNB3.mjs";

// src/Ord.ts
var Ord_exports = {};
__export(Ord_exports, {
  Contravariant: () => Contravariant,
  URI: () => URI,
  between: () => between,
  clamp: () => clamp,
  contramap: () => contramap,
  equals: () => equals,
  equalsDefault: () => equalsDefault,
  fromCompare: () => fromCompare,
  geq: () => geq,
  getDualOrd: () => getDualOrd,
  getMonoid: () => getMonoid,
  getSemigroup: () => getSemigroup,
  getTupleOrd: () => getTupleOrd,
  gt: () => gt,
  leq: () => leq,
  lt: () => lt,
  max: () => max,
  min: () => min,
  ord: () => ord,
  ordBoolean: () => ordBoolean,
  ordDate: () => ordDate,
  ordNumber: () => ordNumber,
  ordString: () => ordString,
  reverse: () => reverse,
  trivial: () => trivial,
  tuple: () => tuple
});
var equalsDefault = (compare2) => (first, second) => first === second || compare2(first, second) === 0;
var fromCompare = (compare2) => ({
  equals: equalsDefault(compare2),
  compare: (first, second) => first === second ? 0 : compare2(first, second)
});
var tuple = (...ords) => fromCompare((first, second) => {
  let i = 0;
  for (; i < ords.length - 1; i++) {
    const r = ords[i].compare(first[i], second[i]);
    if (r !== 0) {
      return r;
    }
  }
  return ords[i].compare(first[i], second[i]);
});
var reverse = (O) => fromCompare((first, second) => O.compare(second, first));
var contramap_ = (fa, f) => pipe(fa, contramap(f));
var contramap = (f) => (fa) => fromCompare((first, second) => fa.compare(f(first), f(second)));
var URI = "Ord";
var getSemigroup = () => ({
  concat: (first, second) => fromCompare((a, b) => {
    const ox = first.compare(a, b);
    return ox !== 0 ? ox : second.compare(a, b);
  })
});
var getMonoid = () => ({
  concat: getSemigroup().concat,
  empty: fromCompare(() => 0)
});
var Contravariant = {
  URI,
  contramap: contramap_
};
var trivial = {
  equals: constTrue,
  compare: /* @__PURE__ */ constant(0)
};
var equals = (O) => (second) => (first) => first === second || O.compare(first, second) === 0;
var lt = (O) => (first, second) => O.compare(first, second) === -1;
var gt = (O) => (first, second) => O.compare(first, second) === 1;
var leq = (O) => (first, second) => O.compare(first, second) !== 1;
var geq = (O) => (first, second) => O.compare(first, second) !== -1;
var min = (O) => (first, second) => first === second || O.compare(first, second) < 1 ? first : second;
var max = (O) => (first, second) => first === second || O.compare(first, second) > -1 ? first : second;
var clamp = (O) => {
  const minO = min(O);
  const maxO = max(O);
  return (low, hi) => (a) => maxO(minO(a, hi), low);
};
var between = (O) => {
  const ltO = lt(O);
  const gtO = gt(O);
  return (low, hi) => (a) => ltO(a, low) || gtO(a, hi) ? false : true;
};
var getTupleOrd = tuple;
var getDualOrd = reverse;
var ord = Contravariant;
function compare(first, second) {
  return first < second ? -1 : first > second ? 1 : 0;
}
var strictOrd = {
  equals: eqStrict.equals,
  compare
};
var ordBoolean = strictOrd;
var ordString = strictOrd;
var ordNumber = strictOrd;
var ordDate = /* @__PURE__ */ pipe(
  ordNumber,
  /* @__PURE__ */ contramap((date) => date.valueOf())
);

export {
  equalsDefault,
  fromCompare,
  tuple,
  reverse,
  contramap,
  URI,
  getSemigroup,
  getMonoid,
  Contravariant,
  trivial,
  equals,
  lt,
  gt,
  leq,
  geq,
  min,
  max,
  clamp,
  between,
  getTupleOrd,
  getDualOrd,
  ord,
  ordBoolean,
  ordString,
  ordNumber,
  ordDate,
  Ord_exports
};
