UNPKG

ramda-extension

Version:

Helpful functions built on top of the mighty Ramda

32 lines (31 loc) 1.17 kB
import { converge, compose, call, juxt, cond, map, last } from 'ramda'; import applyCompose from './applyCompose'; import xPairs from './xPairs'; var getPredicates = /*#__PURE__*/compose( /*#__PURE__*/map( /*#__PURE__*/juxt([applyCompose, last])), xPairs); /** * Returns first result from evaluation of functions in the list, that satisfies predicate. * Returns `undefined` otherwise. * * @func * @category Function * @see dispatch * * @param {function} predicate Predicate that is applied to result of calling fn from `listFns` with `values` * @param {array} listFns List of functions * @param {*} values Values applied to functions from `listFns` * @return {any} Returns first result of calling fn from `listFns` with `values` that satisfies `predicate`. * * @example * * const firstTruthy = R_.dispatchWith(Boolean)([ * prop("foo"), * prop("bar"), * ]) * * firstTruthy({foo: "foo", bar: false}) // "foo" * firstTruthy({foo: false, bar: "bar" }) // "bar" * * @sig [a] -> b|undefined */ var dispatchWith = /*#__PURE__*/converge( /*#__PURE__*/call(cond), [getPredicates]); export default dispatchWith;