bodar/totallylazy

Sequence.take(N) actually takes N+1 items

Closed this issue · 2 comments

Tested with version 2.201

import static com.googlecode.totallylazy.Sequences.repeat;

public class Main {
    static class Dangerous {
        public Dangerous() {
            throw new RuntimeException();
        }
    }

    public static void main(String[] args) {
        repeat(Dangerous::new).take(0).toList();
    }
}

produces

Exception in thread "main" java.lang.RuntimeException
    at Main$Dangerous.<init>(Main.java:6)
    at com.googlecode.totallylazy.functions.Functions.call(Functions.java:39)
    at com.googlecode.totallylazy.Callers.call(Callers.java:87)
    at com.googlecode.totallylazy.iterators.RepeatIterator.next(RepeatIterator.java:19)
    at com.googlecode.totallylazy.iterators.TakeWhileIterator.getNext(TakeWhileIterator.java:19)
    at com.googlecode.totallylazy.iterators.StatefulIterator.hasNext(StatefulIterator.java:23)
    at com.googlecode.totallylazy.Iterators.toList(Iterators.java:247)
    at com.googlecode.totallylazy.Sequences.toList(Sequences.java:382)
    at com.googlecode.totallylazy.Sequence.toList(Sequence.java:269)
    at Main.main(Main.java:11)

Fixed in version 2.202. Thanks for taking the time to bug report.

Thanks for an awesome library.