moltres-utils
Version:
Utils for Moltres apps
62 lines (51 loc) • 2.54 kB
JavaScript
require("core-js/modules/es6.object.define-property");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _all = _interopRequireDefault(require("../common/all"));
var _curry = _interopRequireDefault(require("../common/curry"));
var _defn = _interopRequireDefault(require("../common/defn"));
var _isArrayLike = _interopRequireDefault(require("../lang/isArrayLike"));
var _pipe = _interopRequireDefault(require("../common/pipe"));
var _reduce = _interopRequireDefault(require("./reduce"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// TODO BRN: Performance of this method can be improved by not collecting all the Promises into a new object when resolving them. Instead we should use either generators or transducers to process each value.
/**
* Takes a function and a [functor](https://github.com/fantasyland/fantasy-land#functor), applies the function to each of the functor's values, and returns a functor of the same shape.
*
* Provides suitable `map` implementations for `Array` and `Object`,
* so this function may be applied to `[1, 2, 3]` or `{x: 1, y: 2, z: 3}`.
*
* Dispatches to the `mapAll` method of the second argument, if present.
*
* This method automatically upgrades to async.
* - If the `iteratee` or the `collection` arguments are Promises, this method will resolve those values before executing and this method will return a `Promise`.
* - If the `iteratee` returns a `Promise`, this method will reutrn a `Promise`
*
* This method executes in **parallel**. If the iteratee returns a `Promise`, it will NOT wait till the `Promise` resolves before it executes the next iteration.
*
* @function
* @since v0.0.19
* @category data
* @param {Function} iteratee The function to be called on every element of the input `list`.
* @param {*} collection The collection to be iterated over.
* @return {*} The new collection.
* @example
*
* const double = x => x * 2
*
* mapAll(double, [1, 2, 3]) //=> [2, 4, 6]
*
* mapAll(double, {x: 1, y: 2, z: 3}) //=> {x: 2, y: 4, z: 6}
*/
var mapAll = (0, _curry.default)((0, _defn.default)('mapAll', function (iteratee, collection) {
return (0, _pipe.default)((0, _reduce.default)(function (accum, value, kdx) {
accum[kdx] = iteratee(value, kdx);
return accum;
}, (0, _isArrayLike.default)(collection) ? [] : {}), _all.default)(collection);
}));
var _default = mapAll;
exports.default = _default;
//# sourceMappingURL=mapAll.js.map
;