This package brings goodies of functional programming (map, filter, reduce) to node streams.
npm install --save object-stream-tools
Converts existing array to stream of objects. Useful if you want to inject/merge those object to the existing stream.
const ost =ost
foo: 'bar' web: 'scale'
Its very useful if you want to get unique elements / set of values
const jsonStream =fs
If you just want to remove some objects from stream, you probably want to use filter function.
fs// here you will get filtered objects
Map is useful when you want to modify existing objects in the stream.
Reduce is useful if you want to get single object/value based on whole stream, but you dont want to load whole stream to memory.
Example: sum / average value of huge stream
const jsonStream =fs// pick required property you want to reduce over
Here is example with buffered/string input output:
const jsonStream =fs)
Please note that if you do not pass initial value reduce function will start in (prev, curr, i) mode. Objects/Array/Reduce
promise to stream
It is a useful helper if you dealing with a lot of smaller data that are wrapped in Promise API, ex:
stream to promise
Very handy when you want to consume streams but rest of your application logic uses promises.
Find is super handy if we want to quickly check if vale/objects exists in the stream. Think about it as a grep on the steroids.