mirror of
https://github.com/swc-project/swc.git
synced 2024-12-21 12:41:54 +03:00
bbaf619f63
swc_bundler: - [x] Fix wrapped esms. (denoland/deno#9307) - [x] Make test secure.
52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
// 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;
|