source: node_modules/ramda-adjunct/lib/unzipObjWith.js@ 65b6638

main
Last change on this file since 65b6638 was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.3 KB
Line 
1"use strict";
2
3exports.__esModule = true;
4exports["default"] = void 0;
5var _ramda = require("ramda");
6var _lengthEq = _interopRequireDefault(require("./lengthEq"));
7function _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 */
25var 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});
30var _default = unzipObjWith;
31exports["default"] = _default;
Note: See TracBrowser for help on using the repository browser.