streduce
This library provides provides implementation of reduce abstraction defined by reducers for streams. Which basically means that importing this library will make all node streams reducibles, in other words all of the functions that work with reducers will work with node streams too.
Example
var fs = var fold = var expand = var map = var take = var drop = // You need to import this, otherwise streams are treated as single// value sequences of that value.var Stream = var stream = fs// Map buffer stream to stringsvar stringStream = // Expands text content to a lines. Expand is just like map with// a differenc that mapped values are sequences too, that includes// arrays, streams, arguments, etc...// Some other languages call this operation mapcatvar linesStream = var linesFrom4 = // Take takes `n` number from items from the sequence, there// for we end up with two lines from the package.jsonvar lines56 = // Finally read print lines we're interested in:// => info: line #1 "version": "0.0.1",// => info: line #2 "description": "Adapter for making node streams reducible",
Please note that unlike typical data structures provided by reducers
that ary lazy and do work only after calling reduce
on them, node streams
are not. Things like fs.createReadStream
start reading, that is also how
transformations are applied by reducers library.
Install
npm install streduce