dtao / lazy.js

Like Underscore, but lazier

Home Page:http://danieltao.com/lazy.js/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for native asynchronous generators

opened this issue · comments

async function* iterateDir(dir) {
    let list = await fs.readdir(dir); // fs-promise implementation of readdir
    for (let file of list) {
        yield file;
    }
}

Lazy.generate(iterateDir('./out'))
  .async(1000) // specifies a 1-second interval between each element
  .map(function(x) { return String.fromCharCode(x + 65); })
  .take(26)
  .each(function(char) { console.log(char); });

I think generators are super suitable to be used with lazy.js . Hope this is going to be implemented! :)