swc/bundler/tests/.cache/deno/d802ec9a09e10f17e42d7e1abc40374079df674c.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

56 lines
1.7 KiB
TypeScript

// Loaded from https://deno.land/x/ramda@v0.27.2/source/mapAccumRight.js
import _curry3 from './internal/_curry3.js';
/**
* The `mapAccumRight` function behaves like a combination of map and reduce; it
* applies a function to each element of a list, passing an accumulating
* parameter from right to left, and returning a final value of this
* accumulator together with the new list.
*
* Similar to [`mapAccum`](#mapAccum), except moves through the input list from
* the right to the left.
*
* The iterator function receives two arguments, *acc* and *value*, and should
* return a tuple *[acc, value]*.
*
* @func
* @memberOf R
* @since v0.10.0
* @category List
* @sig ((acc, x) -> (acc, y)) -> acc -> [x] -> (acc, [y])
* @param {Function} fn The function to be called on every element of the input `list`.
* @param {*} acc The accumulator value.
* @param {Array} list The list to iterate over.
* @return {*} The final, accumulated value.
* @see R.addIndex, R.mapAccum
* @example
*
* const digits = ['1', '2', '3', '4'];
* const appender = (a, b) => [b + a, b + a];
*
* R.mapAccumRight(appender, 5, digits); //=> ['12345', ['12345', '2345', '345', '45']]
* @symb R.mapAccumRight(f, a, [b, c, d]) = [
* f(f(f(a, d)[0], c)[0], b)[0],
* [
* f(a, d)[1],
* f(f(a, d)[0], c)[1],
* f(f(f(a, d)[0], c)[0], b)[1]
* ]
* ]
*/
var mapAccumRight = _curry3(function mapAccumRight(fn, acc, list) {
var idx = list.length - 1;
var result = [];
var tuple = [acc];
while (idx >= 0) {
tuple = fn(tuple[0], list[idx]);
result[idx] = tuple[1];
idx -= 1;
}
return [tuple[0], result];
});
export default mapAccumRight;