mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-01 09:47:56 +08:00
Major update breaking changes: - ESLint 7.0.0 (https://eslint.org/docs/user-guide/migrating-to-7.0.0) now includes .eslint.rc.js in its list, which is fine for us. Other changes are not applicable for us. - eslint-plugin-mocha (https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/CHANGELOG.md#700-may-13-2020) drops support for ESLint <7, but this CL updates to 7+. Other changes are not applicable for us. DISABLE_THIRD_PARTY_CHECK=Updating ESLint R=petermarshall@chromium.org Change-Id: I7760e084ef87f73a92f9ea4e075fb4c065047f5a Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2534873 Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org> Reviewed-by: Peter Marshall <petermarshall@chromium.org>
61 lines
2.2 KiB
JavaScript
61 lines
2.2 KiB
JavaScript
import _clone from "./internal/_clone.js";
|
|
import _curryN from "./internal/_curryN.js";
|
|
import _dispatchable from "./internal/_dispatchable.js";
|
|
import _has from "./internal/_has.js";
|
|
import _reduce from "./internal/_reduce.js";
|
|
import _xreduceBy from "./internal/_xreduceBy.js";
|
|
/**
|
|
* Groups the elements of the list according to the result of calling
|
|
* the String-returning function `keyFn` on each element and reduces the elements
|
|
* of each group to a single value via the reducer function `valueFn`.
|
|
*
|
|
* This function is basically a more general [`groupBy`](#groupBy) function.
|
|
*
|
|
* Acts as a transducer if a transformer is given in list position.
|
|
*
|
|
* @func
|
|
* @memberOf R
|
|
* @since v0.20.0
|
|
* @category List
|
|
* @sig ((a, b) -> a) -> a -> (b -> String) -> [b] -> {String: a}
|
|
* @param {Function} valueFn The function that reduces the elements of each group to a single
|
|
* value. Receives two values, accumulator for a particular group and the current element.
|
|
* @param {*} acc The (initial) accumulator value for each group.
|
|
* @param {Function} keyFn The function that maps the list's element into a key.
|
|
* @param {Array} list The array to group.
|
|
* @return {Object} An object with the output of `keyFn` for keys, mapped to the output of
|
|
* `valueFn` for elements which produced that key when passed to `keyFn`.
|
|
* @see R.groupBy, R.reduce
|
|
* @example
|
|
*
|
|
* const groupNames = (acc, {name}) => acc.concat(name)
|
|
* const toGrade = ({score}) =>
|
|
* score < 65 ? 'F' :
|
|
* score < 70 ? 'D' :
|
|
* score < 80 ? 'C' :
|
|
* score < 90 ? 'B' : 'A'
|
|
*
|
|
* var students = [
|
|
* {name: 'Abby', score: 83},
|
|
* {name: 'Bart', score: 62},
|
|
* {name: 'Curt', score: 88},
|
|
* {name: 'Dora', score: 92},
|
|
* ]
|
|
*
|
|
* reduceBy(groupNames, [], toGrade, students)
|
|
* //=> {"A": ["Dora"], "B": ["Abby", "Curt"], "F": ["Bart"]}
|
|
*/
|
|
|
|
var reduceBy =
|
|
/*#__PURE__*/
|
|
_curryN(4, [],
|
|
/*#__PURE__*/
|
|
_dispatchable([], _xreduceBy, function reduceBy(valueFn, valueAcc, keyFn, list) {
|
|
return _reduce(function (acc, elt) {
|
|
var key = keyFn(elt);
|
|
acc[key] = valueFn(_has(key, acc) ? acc[key] : _clone(valueAcc, [], [], false), elt);
|
|
return acc;
|
|
}, {}, list);
|
|
}));
|
|
|
|
export default reduceBy; |