Transduce Stream
Transform Node.js streams with transducers.
Works with transducers-js or transducers.js or transduce.
var stream = var transducer = // create transducer with transduce, transducers-js or transducers.js processstdinprocessstdin
Example:
var stream = tr = // or transducers-js or transducers.js var trans = tr processstdinprocessstdin
Run to get the squares of numbers passed on stdin
.
$ echo '1 12 7 41' | node square.js
1 144 49 1681
This example makes use of transduce/array to add a new line at the end of the stream and transduce/string to split the input on words (can also split on lines, chars and separators or RegExps).
Or using underarm.
// test.jsvar _r = stream = var transducer = processstdinprocessstdin
Run this from the terminal to calculate a formatted sequence of the first 4 unique squared values.
$ echo '33 27 33 444' | node test.js 1089 729 197136 $ node test.js << EOT12 3233 3333 4312 33 12EOT 144 1024 1089 1849