1 | var _curry1 =
|
2 | /*#__PURE__*/
|
3 | require("./internal/_curry1");
|
4 |
|
5 | var apply =
|
6 | /*#__PURE__*/
|
7 | require("./apply");
|
8 |
|
9 | var curryN =
|
10 | /*#__PURE__*/
|
11 | require("./curryN");
|
12 |
|
13 | var max =
|
14 | /*#__PURE__*/
|
15 | require("./max");
|
16 |
|
17 | var pluck =
|
18 | /*#__PURE__*/
|
19 | require("./pluck");
|
20 |
|
21 | var reduce =
|
22 | /*#__PURE__*/
|
23 | require("./reduce");
|
24 |
|
25 | var keys =
|
26 | /*#__PURE__*/
|
27 | require("./keys");
|
28 |
|
29 | var values =
|
30 | /*#__PURE__*/
|
31 | require("./values"); // Use custom mapValues function to avoid issues with specs that include a "map" key and R.map
|
32 | // delegating calls to .map
|
33 |
|
34 |
|
35 | function mapValues(fn, obj) {
|
36 | return keys(obj).reduce(function (acc, key) {
|
37 | acc[key] = fn(obj[key]);
|
38 | return acc;
|
39 | }, {});
|
40 | }
|
41 | /**
|
42 | * Given a spec object recursively mapping properties to functions, creates a
|
43 | * function producing an object of the same structure, by mapping each property
|
44 | * to the result of calling its associated function with the supplied arguments.
|
45 | *
|
46 | * @func
|
47 | * @memberOf R
|
48 | * @since v0.20.0
|
49 | * @category Function
|
50 | * @sig {k: ((a, b, ..., m) -> v)} -> ((a, b, ..., m) -> {k: v})
|
51 | * @param {Object} spec an object recursively mapping properties to functions for
|
52 | * producing the values for these properties.
|
53 | * @return {Function} A function that returns an object of the same structure
|
54 | * as `spec', with each property set to the value returned by calling its
|
55 | * associated function with the supplied arguments.
|
56 | * @see R.converge, R.juxt
|
57 | * @example
|
58 | *
|
59 | * const getMetrics = R.applySpec({
|
60 | * sum: R.add,
|
61 | * nested: { mul: R.multiply }
|
62 | * });
|
63 | * getMetrics(2, 4); // => { sum: 6, nested: { mul: 8 } }
|
64 | * @symb R.applySpec({ x: f, y: { z: g } })(a, b) = { x: f(a, b), y: { z: g(a, b) } }
|
65 | */
|
66 |
|
67 |
|
68 | var applySpec =
|
69 | /*#__PURE__*/
|
70 | _curry1(function applySpec(spec) {
|
71 | spec = mapValues(function (v) {
|
72 | return typeof v == 'function' ? v : applySpec(v);
|
73 | }, spec);
|
74 | return curryN(reduce(max, 0, pluck('length', values(spec))), function () {
|
75 | var args = arguments;
|
76 | return mapValues(function (f) {
|
77 | return apply(f, args);
|
78 | }, spec);
|
79 | });
|
80 | });
|
81 |
|
82 | module.exports = applySpec; |
\ | No newline at end of file |