[d24f17c] | 1 | import { ifElse, curry, useWith, both, gte, lte, gt } from 'ramda';
|
---|
| 2 | var inRangeImp = ifElse(gte, function () {
|
---|
| 3 | throw new Error('low must not be greater than high in inRange(low, high, value)');
|
---|
| 4 | }, useWith(both, [lte, gt]));
|
---|
| 5 |
|
---|
| 6 | /**
|
---|
| 7 | * Checks if `value` is between `low` and up to but not including `high`.
|
---|
| 8 | *
|
---|
| 9 | * @func inRange
|
---|
| 10 | * @memberOf RA
|
---|
| 11 | * @since {@link https://char0n.github.io/ramda-adjunct/2.7.0|v2.7.0}
|
---|
| 12 | * @category Relation
|
---|
| 13 | * @sig Number -> Number -> Number -> Boolean
|
---|
| 14 | * @param {number} low Start of the range
|
---|
| 15 | * @param {number} high The end of the range
|
---|
| 16 | * @param {number} value The value to test
|
---|
| 17 | * @return {boolean}
|
---|
| 18 | * @throws {Error} When `low` is greater than or equal to `high`
|
---|
| 19 | * @example
|
---|
| 20 | *
|
---|
| 21 | * RA.inRange(0, 5, 3); //=> true
|
---|
| 22 | * RA.inRange(0, 5, 0); //=> true
|
---|
| 23 | * RA.inRange(0, 5, 4); //=> true
|
---|
| 24 | * RA.inRange(0, 5, 5); //=> false
|
---|
| 25 | * RA.inRange(0, 5, -1); //=> false
|
---|
| 26 | */
|
---|
| 27 | export default curry(function (low, high, value) {
|
---|
| 28 | return inRangeImp(low, high)(value);
|
---|
| 29 | }); |
---|