update
This commit is contained in:
parent
d9becc67b6
commit
9308795b8b
964 changed files with 104265 additions and 16 deletions
56
node_modules/ramda/es/mapAccumRight.js
generated
vendored
Normal file
56
node_modules/ramda/es/mapAccumRight.js
generated
vendored
Normal file
|
@ -0,0 +1,56 @@
|
|||
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 =
|
||||
/*#__PURE__*/
|
||||
_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;
|
Loading…
Add table
Add a link
Reference in a new issue