UNPKG

moltres-utils

Version:
67 lines (58 loc) 2.59 kB
"use strict"; 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 _pipe = _interopRequireDefault(require("../common/pipe")); var _reduce = _interopRequireDefault(require("./reduce")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * Iterate over a collection calling a provided function `iteratee` for each element in the collection. * * `iteratee` receives two arguments: *(value, kdx)* * * Note: `forEach` does not skip deleted or unassigned indices (sparse * arrays), unlike the native `Array.prototype.forEach` method. For more * details on this behavior, see: * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach#Description * * Also note that, unlike `Array.prototype.forEach`, this `forEach` returns * the original value. In some libraries this function is named `each`. * * Dispatches to the `forEach` 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 invoke. Receives two arguments, `value` and either `index` for arrays or `key` for objects. * @param {*} collection The collection to iterate over. * @returns {*} The original collection. * @example * * const printXPlusFive = x => console.log(x + 5); * forEachAll(printXPlusFive, [1, 2, 3]); //=> [1, 2, 3] * // logs 6 * // logs 7 * // logs 8 */ var forEachAll = (0, _curry.default)((0, _defn.default)('forEachAll', function (iteratee, collection) { return (0, _pipe.default)((0, _reduce.default)(function (accum, value, kdx) { accum.push(iteratee(value, kdx)); return accum; }, []), _all.default, function () { return collection; })(collection); })); var _default = forEachAll; exports.default = _default; //# sourceMappingURL=forEachAll.js.map