feat: add Sequence.each method for side-effect iteration without list creation

Add a new `each` method to the Sequence class that iterates over elements
calling a provided function for each, serving as a side-effect-only
alternative to `map` when the resulting list is not needed. This is
particularly important for the upcoming change where `map` will return a
new sequence instead of mutating in place, as demonstrated by updating
the README and index examples to use `each` with Fiber.yield. Includes
documentation in the Sequence API reference and three new test cases
covering normal iteration, empty sequences, and non-function argument
error handling.
This commit is contained in:
Thorbjørn Lindeijer
2015-03-28 19:35:20 +00:00
parent adc64d65b9
commit 343bfa7a84
8 changed files with 29 additions and 3 deletions
+3
View File
@@ -0,0 +1,3 @@
var words = ""
["One", "Two", "Three"].each {|word| words = words + word }
IO.print(words) // expect: OneTwoThree
+3
View File
@@ -0,0 +1,3 @@
var i = 0
[].each {|item| i = i + 1 }
IO.print(i) // expect: 0
@@ -0,0 +1 @@
[1, 2, 3].each("string") // expect runtime error: String does not implement 'call(_)'.