feat: add Sequence.list method to collect elements into a new List
Implements a new `list` method on the Sequence class that iterates over all elements and returns them as a freshly created List object. Includes documentation with usage example and a test case using a custom TestSequence class to verify correct behavior.
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
class TestSequence is Sequence {
|
||||
iterate(iterator) {
|
||||
if (iterator == null) return 1
|
||||
if (iterator == 3) return false
|
||||
return iterator + 1
|
||||
}
|
||||
|
||||
iteratorValue(iterator) { iterator }
|
||||
}
|
||||
|
||||
IO.print((new TestSequence).list) // expect: [1, 2, 3]
|
||||
Reference in New Issue
Block a user