forked from ramda/ramda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enabling R.scan to be used as transducer. (ramda#2817)
* Add R.scan transducer tests * R.scan transducer enabler: R.into should always call the @@transducer/init method * enable R.scan as transducer * pull upstream & resolve conflicts * add docs about R.scan can act as a transducer
- Loading branch information
Showing
5 changed files
with
79 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import _curry3 from './_curry3.js'; | ||
import _xfBase from './_xfBase.js'; | ||
|
||
var tInit = '@@transducer/init'; | ||
var tStep = '@@transducer/step'; | ||
|
||
function XScan(reducer, acc, xf) { | ||
this.xf = xf; | ||
this.f = reducer; | ||
this.acc = acc; | ||
} | ||
XScan.prototype[tInit] = function() { | ||
return this.xf[tStep](this.xf[tInit](), this.acc); | ||
}; | ||
XScan.prototype['@@transducer/result'] = _xfBase.result; | ||
XScan.prototype[tStep] = function(result, input) { | ||
if (result['@@transducer/reduced']) { | ||
return result; | ||
} | ||
this.acc = this.f(this.acc, input); | ||
return this.xf[tStep](result, this.acc); | ||
}; | ||
|
||
var _xscan = _curry3(function _xscan(reducer, acc, xf) { | ||
return new XScan(reducer, acc, xf); | ||
}); | ||
export default _xscan; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters