reductionist
A through stream that acts as a streaming equivalent for Javascript's reduce
method, built off @dominictarr's
map-stream.
Installation
npm install reductionist
Usage
reductionist(iterator, memo, [options])
The iterator
callback takes three arguments. memo
is the value of the
existing reduction, num
is the data being input, and next
is a callback
that determines the next value of memo
. It's more or less equivalent to
underscore.js.
This stream'll emit running total of the numbers written to it:
var reduce =es = ;var stream =;stream;stream; // 1stream; // 3stream; // 6stream; // 10stream; // 15
Passing an error to the callback's first parameter will cause the stream to emit it and stop accepting input.
By default, reductionist will output the new value of memo
each time it
changes. But by passing { every: false }
as an option, the stream will only
emit a single data event, once it's been closed: the final value for memo
.
var reduce =request =var stream =request