UNPKG

moltres-utils

Version:
62 lines (53 loc) 2.31 kB
"use strict"; require("core-js/modules/es6.object.define-property"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; 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 }; } /** * 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 `map` 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 **series**. If the iteratee returns a Promise, it will wait till the Promise resolves before it executes the next iteration. * * @function * @since v0.0.13 * @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 * * map(double, [1, 2, 3]) //=> [2, 4, 6] * * map(double, {x: 1, y: 2, z: 3}) //=> {x: 2, y: 4, z: 6} */ var map = (0, _curry.default)((0, _defn.default)('map', function (iteratee, collection) { return (0, _reduce.default)(function (accum, value, kdx) { return (0, _pipe.default)(function () { return iteratee(value, kdx); }, function (result) { accum[kdx] = result; return accum; })(); }, (0, _isArrayLike.default)(collection) ? [] : {}, collection); })); var _default = map; exports.default = _default; //# sourceMappingURL=map.js.map