UNPKG

ramda-extension

Version:

Helpful functions built on top of the mighty Ramda

35 lines (29 loc) 1.03 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 _notNil = _interopRequireDefault(require("./notNil")); var _alwaysNull = _interopRequireDefault(require("./alwaysNull")); /** * Call apply on function if the function is defined. Otherwise do nothing and return null. * * @func * @category Function * * @param {Function} fn The function which will be called with `args` when defined * @param {Array} args The arguments to call `fn` with * @return {*} result The result, equivalent to `fn(...args)` or null * @example * * const nums = [1, 2, 3]; * R_.applyIfNotNil(R.sum, nums) // 6 * R_.applyIfNotNil(undefined, nums) // null * * @sig (*... -> a) -> [*] -> a */ var applyIfNotNil = (0, _ramda.ifElse)(_notNil.default, _ramda.apply, _alwaysNull.default); var _default = applyIfNotNil; exports.default = _default;