UNPKG

1.51 kBJavaScriptView Raw
1var chain =
2/*#__PURE__*/
3require("./chain");
4
5var compose =
6/*#__PURE__*/
7require("./compose");
8
9var map =
10/*#__PURE__*/
11require("./map");
12/**
13 * Returns the right-to-left Kleisli composition of the provided functions,
14 * each of which must return a value of a type supported by [`chain`](#chain).
15 *
16 * `R.composeK(h, g, f)` is equivalent to `R.compose(R.chain(h), R.chain(g), f)`.
17 *
18 * @func
19 * @memberOf R
20 * @since v0.16.0
21 * @category Function
22 * @sig Chain m => ((y -> m z), (x -> m y), ..., (a -> m b)) -> (a -> m z)
23 * @param {...Function} ...functions The functions to compose
24 * @return {Function}
25 * @see R.pipeK
26 * @deprecated since v0.26.0
27 * @example
28 *
29 * // get :: String -> Object -> Maybe *
30 * const get = R.curry((propName, obj) => Maybe(obj[propName]))
31 *
32 * // getStateCode :: Maybe String -> Maybe String
33 * const getStateCode = R.composeK(
34 * R.compose(Maybe.of, R.toUpper),
35 * get('state'),
36 * get('address'),
37 * get('user'),
38 * );
39 * getStateCode({"user":{"address":{"state":"ny"}}}); //=> Maybe.Just("NY")
40 * getStateCode({}); //=> Maybe.Nothing()
41 * @symb R.composeK(f, g, h)(a) = R.chain(f, R.chain(g, h(a)))
42 */
43
44
45function composeK() {
46 if (arguments.length === 0) {
47 throw new Error('composeK requires at least one argument');
48 }
49
50 var init = Array.prototype.slice.call(arguments);
51 var last = init.pop();
52 return compose(compose.apply(this, map(chain, init)), last);
53}
54
55module.exports = composeK;
\No newline at end of file