lazy.js icon indicating copy to clipboard operation
lazy.js copied to clipboard

Lazy.lines.getIterator() not working

Open ffleandro opened this issue 11 years ago • 2 comments

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.

ffleandro avatar Jan 04 '14 21:01 ffleandro

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?

dtao avatar Jan 14 '14 16:01 dtao

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?

ffleandro avatar Jan 31 '14 01:01 ffleandro