UNPKG

f-utility

Version:

functional utilities

27 lines (24 loc) 690 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.choice = exports.__choice = undefined; var _katsuCurry = require("katsu-curry"); /** * takes a function that takes two parameters and returns a ternary result * @method choice * @param {function} cnFn - ternary * @param {*} b - anything * @param {*} a - anything * @returns {*} result * @public * @example * import {choice} from 'f-utility' * const max = choice((a, b) => a > b) * max(500, 20) // 500 * max(20, 500) // 500 */ var __choice = exports.__choice = function __choice(cnFn, b, a) { return cnFn(a, b) ? a : b; }; var choice = exports.choice = (0, _katsuCurry.curry)(__choice);