[d24f17c] | 1 | var _curry2 =
|
---|
| 2 | /*#__PURE__*/
|
---|
| 3 | require("./internal/_curry2.js");
|
---|
| 4 |
|
---|
| 5 | var _isArray =
|
---|
| 6 | /*#__PURE__*/
|
---|
| 7 | require("./internal/_isArray.js");
|
---|
| 8 |
|
---|
| 9 | var _map =
|
---|
| 10 | /*#__PURE__*/
|
---|
| 11 | require("./internal/_map.js");
|
---|
| 12 |
|
---|
| 13 | var _assoc =
|
---|
| 14 | /*#__PURE__*/
|
---|
| 15 | require("./internal/_assoc.js");
|
---|
| 16 | /**
|
---|
| 17 | *
|
---|
| 18 | * Deconstructs an array field from the input documents to output a document for each element.
|
---|
| 19 | * Each output document is the input document with the value of the array field replaced by the element.
|
---|
| 20 | *
|
---|
| 21 | * @func
|
---|
| 22 | * @memberOf R
|
---|
| 23 | * @since v0.28.0
|
---|
| 24 | * @category Object
|
---|
| 25 | * @sig String -> {k: [v]} -> [{k: v}]
|
---|
| 26 | * @param {String} key The key to determine which property of the object should be unwind
|
---|
| 27 | * @param {Object} object The object containing list under property named as key which is to unwind
|
---|
| 28 | * @return {List} A new list of object containing the value of input key having list replaced by each element in the object.
|
---|
| 29 | * @example
|
---|
| 30 | *
|
---|
| 31 | * R.unwind('hobbies', {
|
---|
| 32 | * name: 'alice',
|
---|
| 33 | * hobbies: ['Golf', 'Hacking'],
|
---|
| 34 | * colors: ['red', 'green'],
|
---|
| 35 | * });
|
---|
| 36 | * // [
|
---|
| 37 | * // { name: 'alice', hobbies: 'Golf', colors: ['red', 'green'] },
|
---|
| 38 | * // { name: 'alice', hobbies: 'Hacking', colors: ['red', 'green'] }
|
---|
| 39 | * // ]
|
---|
| 40 | */
|
---|
| 41 |
|
---|
| 42 |
|
---|
| 43 | var unwind =
|
---|
| 44 | /*#__PURE__*/
|
---|
| 45 | _curry2(function (key, object) {
|
---|
| 46 | // If key is not in object or key is not as a list in object
|
---|
| 47 | if (!(key in object && _isArray(object[key]))) {
|
---|
| 48 | return [object];
|
---|
| 49 | } // Map over object[key] which is a list and assoc each element with key
|
---|
| 50 |
|
---|
| 51 |
|
---|
| 52 | return _map(function (item) {
|
---|
| 53 | return _assoc(key, item, object);
|
---|
| 54 | }, object[key]);
|
---|
| 55 | });
|
---|
| 56 |
|
---|
| 57 | module.exports = unwind; |
---|