UNPKG

ramda-extension

Version:

Helpful functions built on top of the mighty Ramda

40 lines (34 loc) 1.2 kB
"use strict"; 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 `x` is a function then we return the result of calling `x` with the remaining arguments. * If `x` is not a function then we return it as it is. * * @func * @category Function * * @param {any} x Function or value * @param {*} args Any number of positional arguments. * @returns {any} * * @example * const ref = { current: null }; * const getRef = always(ref); * const createRef = (current) => ({ current }); * * R_.callIfFunction(ref); // { current: null } * R_.callIfFunction(getRef); // { current: null } * R_.callIfFunction(createRef, document.body); // {"current": [object HTMLBodyElement]} * * @sig (a|(*... -> a),*...) -> a */ var callIfFunction = (0, _ramda.ifElse)(_isFunction.default, _ramda.call, _headArg.default); var _default = callIfFunction; exports.default = _default;