feat: add Sequence.each method to iterate over elements with a function
Add a new `each` method to the Sequence class in the Wren programming language, allowing iteration over sequence elements by passing each element to a provided function. This replaces the previous pattern of using `map` with `Fiber.yield` in examples, providing a more direct and idiomatic way to perform side effects per element. The implementation includes a core library method in `core.wren`, a C source string in `wren_core.c`, documentation in the Sequence markdown file, and three test cases covering normal iteration, empty sequences, and non-function argument error handling.
This commit is contained in:
@@ -40,6 +40,12 @@ class Sequence {
|
||||
return result
|
||||
}
|
||||
|
||||
each(f) {
|
||||
for (element in this) {
|
||||
f.call(element)
|
||||
}
|
||||
}
|
||||
|
||||
map(f) {
|
||||
var result = new List
|
||||
for (element in this) {
|
||||
|
||||
Reference in New Issue
Block a user