[d24f17c] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | exports.__esModule = true;
|
---|
| 4 | exports["default"] = void 0;
|
---|
| 5 | var _ramda = require("ramda");
|
---|
| 6 | var _lengthEq = _interopRequireDefault(require("./lengthEq"));
|
---|
| 7 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
---|
| 8 | /**
|
---|
| 9 | * Creates a new list out of the supplied object by applying the function to each key/value pairing.
|
---|
| 10 | *
|
---|
| 11 | * @func unzipObjWith
|
---|
| 12 | * @memberOf RA
|
---|
| 13 | * @category Object
|
---|
| 14 | * @since {@link https://char0n.github.io/ramda-adjunct/2.22.0|v2.22.0}
|
---|
| 15 | * @sig (v, k) => [k, v] -> { k: v } -> [[k], [v]]
|
---|
| 16 | * @param {Function} fn The function to transform each value-key pair
|
---|
| 17 | * @param {Object} obj Object to unzip
|
---|
| 18 | * @return {Array} A pair of tw lists: a list of keys and a list of values
|
---|
| 19 | * @see {@link https://ramdajs.com/docs/#zipObj|zipObj}, {@link RA.zipObjWith|zipObjWith}
|
---|
| 20 | * @example
|
---|
| 21 | *
|
---|
| 22 | * RA.unzipObjWith((v, k) => [`new${k.toUpperCase()}`, 2 * v], { a: 1, b: 2, c: 3 });
|
---|
| 23 | * //=> [['newA', 'newB', 'newC'], [2, 4, 6]]
|
---|
| 24 | */
|
---|
| 25 | var unzipObjWith = (0, _ramda.curryN)(2, function (fn, obj) {
|
---|
| 26 | return (0, _ramda.pipe)(_ramda.toPairs, (0, _ramda.map)((0, _ramda.pipe)(_ramda.flip, _ramda.apply)(fn)), _ramda.transpose, (0, _ramda.when)((0, _lengthEq["default"])(0), function () {
|
---|
| 27 | return [[], []];
|
---|
| 28 | }))(obj);
|
---|
| 29 | });
|
---|
| 30 | var _default = unzipObjWith;
|
---|
| 31 | exports["default"] = _default; |
---|