swc/crates/swc_bundler/tests/.cache/deno/a8cbff1a9e1020dacbcd6a03ae67dc7e6a73d859.ts

52 lines
1.5 KiB
TypeScript
Raw Normal View History

// Loaded from https://deno.land/x/ramda@v0.27.2/source/forEach.js
import _checkForMethod from './internal/_checkForMethod.js';
import _curry2 from './internal/_curry2.js';
/**
* Iterate over an input `list`, calling a provided function `fn` for each
* element in the list.
*
* `fn` receives one argument: *(value)*.
*
* Note: `R.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`, Ramda's `forEach` returns
* the original array. In some libraries this function is named `each`.
*
* Dispatches to the `forEach` method of the second argument, if present.
*
* @func
* @memberOf R
* @since v0.1.1
* @category List
* @sig (a -> *) -> [a] -> [a]
* @param {Function} fn The function to invoke. Receives one argument, `value`.
* @param {Array} list The list to iterate over.
* @return {Array} The original list.
* @see R.addIndex
* @example
*
* const printXPlusFive = x => console.log(x + 5);
* R.forEach(printXPlusFive, [1, 2, 3]); //=> [1, 2, 3]
* // logs 6
* // logs 7
* // logs 8
* @symb R.forEach(f, [a, b, c]) = [a, b, c]
*/
var forEach = _curry2(_checkForMethod('forEach', function forEach(fn, list) {
var len = list.length;
var idx = 0;
while (idx < len) {
fn(list[idx]);
idx += 1;
}
return list;
}));
export default forEach;