test-action-debian-package/node_modules/ramda/es/composeK.js

44 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-03-26 14:37:35 +00:00
import chain from "./chain.js";
import compose from "./compose.js";
import map from "./map.js";
/**
* Returns the right-to-left Kleisli composition of the provided functions,
* each of which must return a value of a type supported by [`chain`](#chain).
*
* `R.composeK(h, g, f)` is equivalent to `R.compose(R.chain(h), R.chain(g), f)`.
*
* @func
* @memberOf R
* @since v0.16.0
* @category Function
* @sig Chain m => ((y -> m z), (x -> m y), ..., (a -> m b)) -> (a -> m z)
* @param {...Function} ...functions The functions to compose
* @return {Function}
* @see R.pipeK
* @deprecated since v0.26.0
* @example
*
* // get :: String -> Object -> Maybe *
* const get = R.curry((propName, obj) => Maybe(obj[propName]))
*
* // getStateCode :: Maybe String -> Maybe String
* const getStateCode = R.composeK(
* R.compose(Maybe.of, R.toUpper),
* get('state'),
* get('address'),
* get('user'),
* );
* getStateCode({"user":{"address":{"state":"ny"}}}); //=> Maybe.Just("NY")
* getStateCode({}); //=> Maybe.Nothing()
* @symb R.composeK(f, g, h)(a) = R.chain(f, R.chain(g, h(a)))
*/
export default function composeK() {
if (arguments.length === 0) {
throw new Error('composeK requires at least one argument');
}
var init = Array.prototype.slice.call(arguments);
var last = init.pop();
return compose(compose.apply(this, map(chain, init)), last);
}