feat: replace eager map/where with lazy MapSequence and WhereSequence classes
Refactor Sequence.map and Sequence.where to return lazy MapSequence and WhereSequence wrappers instead of eagerly building a List. Add new MapSequence and WhereSequence classes that delegate iteration and apply the transformation or predicate on-the-fly. Update documentation to reflect lazy semantics and the need to call .list to materialize results. Adjust all existing tests to call .list on map/where results. Add new tests in test/core/sequence/ verifying lazy behavior with infinite Fibonacci iterators.
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
var a = [1, 2, 3]
|
||||
var b = a.map {|x| x + 1 }
|
||||
var b = a.map {|x| x + 1 }.list
|
||||
IO.print(b) // expect: [2, 3, 4]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var a = [1, 2, 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: []
|
||||
|
||||
Reference in New Issue
Block a user