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