mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-12 17:45:49 +08:00
DISABLE_THIRD_PARTY_CHECK=new npm module causes package-lock change We can get rid of a custom script and use ESLint for these rules. Additionally this means editors will highlight the issue in the editor. Change-Id: I552b52e7f07b4e7430b3f685dbc3b5fad36ffff2 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2052167 Reviewed-by: Paul Lewis <aerotwist@chromium.org> Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
49 lines
1.5 KiB
JavaScript
49 lines
1.5 KiB
JavaScript
import _curry3 from './internal/_curry3.js';
|
|
|
|
/**
|
|
* The `mapAccum` function behaves like a combination of map and reduce; it
|
|
* applies a function to each element of a list, passing an accumulating
|
|
* parameter from left to right, and returning a final value of this
|
|
* accumulator together with the new list.
|
|
*
|
|
* 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.scan, R.addIndex, R.mapAccumRight
|
|
* @example
|
|
*
|
|
* const digits = ['1', '2', '3', '4'];
|
|
* const appender = (a, b) => [a + b, a + b];
|
|
*
|
|
* R.mapAccum(appender, 0, digits); //=> ['01234', ['01', '012', '0123', '01234']]
|
|
* @symb R.mapAccum(f, a, [b, c, d]) = [
|
|
* f(f(f(a, b)[0], c)[0], d)[0],
|
|
* [
|
|
* f(a, b)[1],
|
|
* f(f(a, b)[0], c)[1],
|
|
* f(f(f(a, b)[0], c)[0], d)[1]
|
|
* ]
|
|
* ]
|
|
*/
|
|
var mapAccum = /*#__PURE__*/_curry3(function mapAccum(fn, acc, list) {
|
|
var idx = 0;
|
|
var len = list.length;
|
|
var result = [];
|
|
var tuple = [acc];
|
|
while (idx < len) {
|
|
tuple = fn(tuple[0], list[idx]);
|
|
result[idx] = tuple[1];
|
|
idx += 1;
|
|
}
|
|
return [tuple[0], result];
|
|
});
|
|
export default mapAccum; |