ramda-extension
Version:
Helpful functions built on top of the mighty Ramda
40 lines (34 loc) • 1.22 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _ramda = require("ramda");
var _isFunction = _interopRequireDefault(require("./isFunction"));
var _headArg = _interopRequireDefault(require("./headArg"));
/**
* If the first argument is a function then we apply the function with args that are passed as the second argument.
* If the first argument is not a function then we return it as it is.
*
* @func
* @category Function
*
* @param {any} x Function or value
* @param {array} args Array of arguments
* @returns {any}
*
* @example
* const ref = { current: null };
* const getRef = always(ref);
* const createRef = (current) => ({ current });
*
* R_.applyIfFunction(ref, []); // { current: null }
* R_.applyIfFunction(getRef, []); // { current: null }
* R_.applyIfFunction(createRef, [document.body]); // {"current": [object HTMLBodyElement]}
*
* @sig a|(*... -> a) -> [*] -> a
*/
var applyIfFunction = (0, _ramda.ifElse)(_isFunction.default, _ramda.apply, _headArg.default);
var _default = applyIfFunction;
exports.default = _default;