Last active
August 29, 2015 14:10
-
-
Save hekike/f8a8c67dd9092265c9c2 to your computer and use it in GitHub Desktop.
such frp code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var util = require('util'); | |
var fs = require('fs'); | |
var es = require('event-stream'); | |
var request = require('request'); | |
function nicely(data, cb) { | |
cb(null, util.inspect(data)); | |
} | |
function filterOutEmpty (data, cb){ | |
cb(null, data.length ? data : undefined); | |
} | |
function breakToLine (line, cb) { | |
cb(null, line + '\n'); | |
} | |
function getProfile (user, cb) { | |
if(!user.name) { | |
return cb(); | |
} | |
var options = { | |
url: 'https://api.github.com/users/' + user.name, | |
headers: { | |
'User-Agent': 'request' | |
} | |
}; | |
request(options, function (err, res, body) { | |
cb(err, body); | |
}); | |
} | |
function pickMeta (user, cb) { | |
if(!user.name || !user.email) { | |
return cb(); | |
} | |
cb(null, { name: user.name, email: user.email }); | |
} | |
// Such stream | |
es.pipe( | |
es.merge( | |
fs.createReadStream('data1.json'), | |
fs.createReadStream('data2.json') | |
), | |
es.split('\n'), | |
es.map(filterOutEmpty), | |
es.parse(), | |
es.map(getProfile), | |
es.parse(), | |
es.map(pickMeta), | |
es.map(nicely), | |
es.map(breakToLine), | |
process.stdout | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ "name": "substack" } | |
{ "name": "dominictarr" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ "name": "mikeal" } | |
{ "name": "indutny" } | |
{ "name": "dead-horse" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "such-frp", | |
"version": "0.0.0", | |
"main": "app.js", | |
"dependencies": { | |
"event-stream": "^3.1.7", | |
"request": "^2.49.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment