swc/bundler/tests/.cache/deno/6a47f3c7ed4eb9ae67e93fca98d56bfbb86ecf62.ts
강동윤 bbaf619f63
fix(bundler): Fix bugs (#1437)
swc_bundler:
 - [x] Fix wrapped esms. (denoland/deno#9307)
 - [x] Make test secure.
2021-03-02 17:33:03 +09:00

40 lines
1.1 KiB
TypeScript

// Loaded from https://deno.land/x/ramda@v0.27.2/source/scan.js
import _curry3 from './internal/_curry3.js';
/**
* Scan is similar to [`reduce`](#reduce), but returns a list of successively
* reduced values from the left
*
* @func
* @memberOf R
* @since v0.10.0
* @category List
* @sig ((a, b) -> a) -> a -> [b] -> [a]
* @param {Function} fn The iterator function. Receives two values, the accumulator and the
* current element from the array
* @param {*} acc The accumulator value.
* @param {Array} list The list to iterate over.
* @return {Array} A list of all intermediately reduced values.
* @see R.reduce, R.mapAccum
* @example
*
* const numbers = [1, 2, 3, 4];
* const factorials = R.scan(R.multiply, 1, numbers); //=> [1, 1, 2, 6, 24]
* @symb R.scan(f, a, [b, c]) = [a, f(a, b), f(f(a, b), c)]
*/
var scan = _curry3(function scan(fn, acc, list) {
var idx = 0;
var len = list.length;
var result = [acc];
while (idx < len) {
acc = fn(acc, list[idx]);
result[idx + 1] = acc;
idx += 1;
}
return result;
});
export default scan;