Adapter for making node streams reducible
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.
var fs = require"fs"var fold = require"reducers/fold"var expand = require"reducers/expand"var map = require"reducers/map"var take = require"reducers/take"var drop = require"reducers/drop"// You need to import this, otherwise streams are treated as single// value sequences of that value.var Stream = require"streduce"var stream = fscreateReadStream"./package.json"// Map buffer stream to stringsvar stringStream = mapstream String// 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 = expandstringStreamreturn textsplit"\n"var linesFrom4 = droplinesStream 3// Take takes `n` number from items from the sequence, there// for we end up with two lines from the package.jsonvar lines56 = takelinesFrom4 2// Finally read print lines we're interested in:foldlines56console.log"line #" + ++count + " " + linereturn count0// => 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.
npm install streduce