Skip to content

Instantly share code, notes, and snippets.

@pkrumins
Created October 10, 2010 23:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkrumins/619702 to your computer and use it in GitHub Desktop.
Save pkrumins/619702 to your computer and use it in GitHub Desktop.
pkrumins@stackvm:~/projects/node-lazy$ cat tests/filter.js
var Lazy = require('lazy');
var EventEmitter = require('events').EventEmitter;
function range(i, j) {
var r = [];
for (;i<j;i++) r.push(i);
return r;
}
var lazy = new Lazy;
lazy.filter(function(x) { return x > 5 }).map(function (x) { return x*2 }).take(2).forEach(function (x) {
console.log(x);
});
range(0,10).forEach(function (x) {
lazy.emit('data', x);
});
pkrumins@stackvm:~/projects/node-lazy$ node tests/filter.js
12
14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment