[d24f17c] | 1 | var _checkForMethod =
|
---|
| 2 | /*#__PURE__*/
|
---|
| 3 | require("./internal/_checkForMethod.js");
|
---|
| 4 |
|
---|
| 5 | var _curry2 =
|
---|
| 6 | /*#__PURE__*/
|
---|
| 7 | require("./internal/_curry2.js");
|
---|
| 8 | /**
|
---|
| 9 | * Iterate over an input `list`, calling a provided function `fn` for each
|
---|
| 10 | * element in the list.
|
---|
| 11 | *
|
---|
| 12 | * `fn` receives one argument: *(value)*.
|
---|
| 13 | *
|
---|
| 14 | * Note: `R.forEach` does not skip deleted or unassigned indices (sparse
|
---|
| 15 | * arrays), unlike the native `Array.prototype.forEach` method. For more
|
---|
| 16 | * details on this behavior, see:
|
---|
| 17 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach#Description
|
---|
| 18 | *
|
---|
| 19 | * Also note that, unlike `Array.prototype.forEach`, Ramda's `forEach` returns
|
---|
| 20 | * the original array. In some libraries this function is named `each`.
|
---|
| 21 | *
|
---|
| 22 | * Dispatches to the `forEach` method of the second argument, if present.
|
---|
| 23 | *
|
---|
| 24 | * @func
|
---|
| 25 | * @memberOf R
|
---|
| 26 | * @since v0.1.1
|
---|
| 27 | * @category List
|
---|
| 28 | * @sig (a -> *) -> [a] -> [a]
|
---|
| 29 | * @param {Function} fn The function to invoke. Receives one argument, `value`.
|
---|
| 30 | * @param {Array} list The list to iterate over.
|
---|
| 31 | * @return {Array} The original list.
|
---|
| 32 | * @see R.addIndex
|
---|
| 33 | * @example
|
---|
| 34 | *
|
---|
| 35 | * const printXPlusFive = x => console.log(x + 5);
|
---|
| 36 | * R.forEach(printXPlusFive, [1, 2, 3]); //=> [1, 2, 3]
|
---|
| 37 | * // logs 6
|
---|
| 38 | * // logs 7
|
---|
| 39 | * // logs 8
|
---|
| 40 | * @symb R.forEach(f, [a, b, c]) = [a, b, c]
|
---|
| 41 | */
|
---|
| 42 |
|
---|
| 43 |
|
---|
| 44 | var forEach =
|
---|
| 45 | /*#__PURE__*/
|
---|
| 46 | _curry2(
|
---|
| 47 | /*#__PURE__*/
|
---|
| 48 | _checkForMethod('forEach', function forEach(fn, list) {
|
---|
| 49 | var len = list.length;
|
---|
| 50 | var idx = 0;
|
---|
| 51 |
|
---|
| 52 | while (idx < len) {
|
---|
| 53 | fn(list[idx]);
|
---|
| 54 | idx += 1;
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | return list;
|
---|
| 58 | }));
|
---|
| 59 |
|
---|
| 60 | module.exports = forEach; |
---|