source: node_modules/ramda/src/internal/_xreduceBy.js

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

Initial commit

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