source: node_modules/ramda/es/forEach.js

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

Initial commit

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