[d24f17c] | 1 | import _clone from "./_clone.js";
|
---|
| 2 | import _has from "./_has.js";
|
---|
| 3 | import _xfBase from "./_xfBase.js";
|
---|
| 4 |
|
---|
| 5 | var XReduceBy =
|
---|
| 6 | /*#__PURE__*/
|
---|
| 7 | function () {
|
---|
| 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 |
|
---|
| 46 | export default function _xreduceBy(valueFn, valueAcc, keyFn) {
|
---|
| 47 | return function (xf) {
|
---|
| 48 | return new XReduceBy(valueFn, valueAcc, keyFn, xf);
|
---|
| 49 | };
|
---|
| 50 | } |
---|