feat: replace eager list-based map/where with deferred MapSequence and WhereSequence classes

Introduce MapSequence and WhereSequence subclasses of Sequence that apply transformations lazily during iteration instead of building intermediate lists. Update Sequence.map and Sequence.where to return these deferred wrappers, modify all existing tests to call .list on results, and add new infinite-sequence tests verifying lazy behavior on Fibonacci iterators.
This commit is contained in:
Thorbjørn Lindeijer
2015-03-28 21:51:50 +00:00
parent adc64d65b9
commit 5b71ac0c56
9 changed files with 160 additions and 44 deletions
+1 -1
View File
@@ -1,3 +1,3 @@
var a = 1..3
var b = a.map {|x| x + 1 }
var b = a.map {|x| x + 1 }.list
IO.print(b) // expect: [2, 3, 4]
+2 -2
View File
@@ -1,6 +1,6 @@
var a = 1..3
var b = a.where {|x| x > 1 }
var b = a.where {|x| x > 1 }.list
IO.print(b) // expect: [2, 3]
var c = a.where {|x| x > 10 }
var c = a.where {|x| x > 10 }.list
IO.print(c) // expect: []