Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy.lines.getIterator() not working #63

Open
ffleandro opened this issue Jan 4, 2014 · 2 comments
Open

Lazy.lines.getIterator() not working #63

ffleandro opened this issue Jan 4, 2014 · 2 comments

Comments

@ffleandro
Copy link

This example prints nothing.

var Lazy = require('lazy.js');

var it = Lazy.readFile("log.txt")
            .lines()
            .getIterator();

while(it.moveNext()){
    console.log(it.current());
}

Altough this example works correctly:

var Lazy = require('lazy.js');

Lazy.readFile("log.txt")
        .lines()
        .each(function(line){
            console.log(line);
        });

I'm using version 0.3.1 installed from npm.

@dtao
Copy link
Owner

dtao commented Jan 14, 2014

I apologize for not responding to this (directly) sooner. As you can see in the commit from 6 days ago, I have updated the documentation to explain that getIterator isn't really meant to be used directly. Maybe for that reason I should rename it to _getIterator or something.

Anyway, I've responded to your question on StackOverflow to hopefully explain what you're seeing here.

Is there any reason you want to use getIterator instead of each? Or were you just experimenting?

@ffleandro
Copy link
Author

Than you for you answer.
As i've explained in the StackOverflow thread, I needed to use getIterator because I didn't want to read all the lines of a file. I needed to read the first line of n different files and process the one with the smallest timestamp until there was no lines to read from any file. For that specific scenario I needed to use getIterator.

Is it possible to implement getIterator on a Stream Sequence?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants