"use strict"
Object.defineProperty(exports, "__esModule", { value: true })
exports.getEqual =
  exports.inverted =
  exports.clamp =
  exports.between =
  exports.min =
  exports.max =
  exports.lt =
  exports.leq =
  exports.gt =
  exports.contramap_ =
  exports.contramap =
  exports.makeOrd =
    void 0
const Equal_1 = require("../Equal")
/**
 * Creates Ord[A] from a compare function
 */
function makeOrd(compare) {
  return {
    compare
  }
}
exports.makeOrd = makeOrd
/**
 * Contramap Ord input
 */
function contramap(f) {
  return (fa) => contramap_(fa, f)
}
exports.contramap = contramap
/**
 * Contramap Ord input
 */
function contramap_(fa, f) {
  return makeOrd((x, y) => fa.compare(f(x), f(y)))
}
exports.contramap_ = contramap_
/**
 * Test whether one value is _strictly greater than_ another
 */
function gt(O) {
  return (x, y) => O.compare(x, y) === 1
}
exports.gt = gt
/**
 * Test whether one value is _non-strictly less than_ another
 */
function leq(O) {
  return (x, y) => O.compare(x, y) !== 1
}
exports.leq = leq
/**
 * Test whether one value is _strictly less than_ another
 */
function lt(O) {
  return (x, y) => O.compare(x, y) === -1
}
exports.lt = lt
/**
 * Take the maximum of two values. If they are considered equal, the first argument is chosen
 */
function max(O) {
  return (x, y) => (O.compare(x, y) === -1 ? y : x)
}
exports.max = max
/**
 * Take the minimum of two values. If they are considered equal, the first argument is chosen
 */
function min(O) {
  return (x, y) => (O.compare(x, y) === 1 ? y : x)
}
exports.min = min
/**
 * Test whether a value is between a minimum and a maximum (inclusive)
 */
function between(O) {
  const lessThanO = lt(O)
  const greaterThanO = gt(O)
  return (low, hi) => (x) => lessThanO(x, low) || greaterThanO(x, hi) ? false : true
}
exports.between = between
/**
 * Clamp a value between a minimum and a maximum
 */
function clamp(O) {
  const minO = min(O)
  const maxO = max(O)
  return (low, hi) => (x) => maxO(minO(x, hi), low)
}
exports.clamp = clamp
/**
 * Get the dual of an Ord
 */
function inverted(O) {
  return makeOrd((x, y) => O.compare(y, x))
}
exports.inverted = inverted
/**
 * Get an instance of Equal
 */
function getEqual(O) {
  return (0, Equal_1.makeEqual)((x, y) => O.compare(x, y) === 0)
}
exports.getEqual = getEqual
//# sourceMappingURL=operations.js.map
