source: node_modules/ramda/es/internal/_xreduceBy.js@ d24f17c

main
Last change on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.2 KB
Line 
1import _clone from "./_clone.js";
2import _has from "./_has.js";
3import _xfBase from "./_xfBase.js";
4
5var XReduceBy =
6/*#__PURE__*/
7function () {
8 function XReduceBy(valueFn, valueAcc, keyFn, xf) {
9 this.valueFn = valueFn;
10 this.valueAcc = valueAcc;
11 this.keyFn = keyFn;
12 this.xf = xf;
13 this.inputs = {};
14 }
15
16 XReduceBy.prototype['@@transducer/init'] = _xfBase.init;
17
18 XReduceBy.prototype['@@transducer/result'] = function (result) {
19 var key;
20
21 for (key in this.inputs) {
22 if (_has(key, this.inputs)) {
23 result = this.xf['@@transducer/step'](result, this.inputs[key]);
24
25 if (result['@@transducer/reduced']) {
26 result = result['@@transducer/value'];
27 break;
28 }
29 }
30 }
31
32 this.inputs = null;
33 return this.xf['@@transducer/result'](result);
34 };
35
36 XReduceBy.prototype['@@transducer/step'] = function (result, input) {
37 var key = this.keyFn(input);
38 this.inputs[key] = this.inputs[key] || [key, _clone(this.valueAcc, false)];
39 this.inputs[key][1] = this.valueFn(this.inputs[key][1], input);
40 return result;
41 };
42
43 return XReduceBy;
44}();
45
46export default function _xreduceBy(valueFn, valueAcc, keyFn) {
47 return function (xf) {
48 return new XReduceBy(valueFn, valueAcc, keyFn, xf);
49 };
50}
Note: See TracBrowser for help on using the repository browser.