@dillonkearns/elm-graphql
Version:
<img src="https://cdn.jsdelivr.net/gh/martimatix/logo-graphqelm/logo.svg" alt="dillonearns/elm-graphql logo" width="40%" align="right">
72 lines (58 loc) • 1.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.stringOrd = exports.numberOrd = exports.booleanOrd = undefined;
exports.toNativeComparator = toNativeComparator;
exports.unsafeCompare = unsafeCompare;
exports.lessThan = lessThan;
exports.greaterThan = greaterThan;
exports.lessThanOrEq = lessThanOrEq;
exports.greaterThanOrEq = greaterThanOrEq;
exports.min = min;
exports.max = max;
exports.clamp = clamp;
exports.between = between;
var _Setoid = require('./Setoid');
function toNativeComparator(compare) {
return function (x, y) {
var c = compare(x, y);
return c === 'GT' ? 1 : c === 'EQ' ? 0 : -1;
};
}
function unsafeCompare(x, y) {
return x < y ? 'LT' : x > y ? 'GT' : 'EQ';
}
var booleanOrd = exports.booleanOrd = Object.assign({}, {
compare: unsafeCompare
}, _Setoid.booleanSetoid);
var numberOrd = exports.numberOrd = Object.assign({}, {
compare: unsafeCompare
}, _Setoid.numberSetoid);
var stringOrd = exports.stringOrd = Object.assign({}, {
compare: unsafeCompare
}, _Setoid.stringSetoid);
function lessThan(ord, x, y) {
return ord.compare(x, y) === 'LT';
}
function greaterThan(ord, x, y) {
return ord.compare(x, y) === 'GT';
}
function lessThanOrEq(ord, x, y) {
return ord.compare(x, y) !== 'GT';
}
function greaterThanOrEq(ord, x, y) {
return ord.compare(x, y) !== 'LT';
}
function min(ord, x, y) {
return ord.compare(x, y) === 'GT' ? y : x;
}
function max(ord, x, y) {
return ord.compare(x, y) === 'LT' ? y : x;
}
function clamp(ord, low, hi, x) {
return min(ord, hi, max(ord, low, x));
}
function between(ord, low, hi, x) {
return lessThan(ord, x, low) || greaterThan(ord, x, hi) ? false : true;
}