Laythe-lang/Laythe

Iterator skip & take

Closed this issue · 0 comments

After doing more implementing in Laythe the common iterator methods .take and .skip are becoming more of a pain point. I believe like essentially all iterator methods that don't produces a single value like .reduce .all or .any these methods should be lazy. Below shows what I believe the behavior should be

let l1 = [1, 2, 3].iter();
let s = l1.skip(2);
print(List.collect(s));
// [3]
// l1 is now exhausted

let l2 = [1, 2, 3].iter();
let t = l2.take(2);
print(List.collect(t));
// [1, 2]
// l2 can still yield 3