Skip to content

Instantly share code, notes, and snippets.

@LewisJEllis
Last active July 2, 2016 01:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save LewisJEllis/1ac2e10e9309b3f59017 to your computer and use it in GitHub Desktop.
Save LewisJEllis/1ac2e10e9309b3f59017 to your computer and use it in GitHub Desktop.
Highland reduce example
var express = require('express');
var _ = require('highland');
var fs = require('fs');
var app = express();
function chain(s, f) {
return s.flatMap(_.wrapCallback(f))
}
app.post('/process-file', function(req, res) {
var inputFile = 'input.txt';
var outputFile = 'output.txt';
var data = _([inputFile]);
_([
fs.readFile,
process1,
process2,
process3,
writeToFileName(outputFile)
]).reduce(data, chain).flatten()
.stopOnError(function (err) {
return res.status(500).send(err);
}).apply(function (data) {
return res.status(200).send('processed');
});
});
@eiriklv
Copy link

eiriklv commented Jan 9, 2015

Really helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment