forked from Mirror/wren
@ -90,6 +90,14 @@ class Sequence {
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
list {
|
||||
var result = new List
|
||||
for (element in this) {
|
||||
result.add(element)
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
class String is Sequence {
|
||||
|
||||
@ -65,6 +65,13 @@ It is a runtime error if `sep` is not a string.
|
||||
|
||||
Calls `join` with the empty string as the separator.
|
||||
|
||||
### **list**
|
||||
|
||||
Creates a [list](list.html) containing all the elements in the sequence.
|
||||
|
||||
:::dart
|
||||
(1..3).list // [1, 2, 3]
|
||||
|
||||
### **map**(transformation)
|
||||
|
||||
Creates a new list by applying `transformation` to each element in the
|
||||
|
||||
@ -136,6 +136,14 @@ static const char* libSource =
|
||||
"\n"
|
||||
" return result\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" list {\n"
|
||||
" var result = new List\n"
|
||||
" for (element in this) {\n"
|
||||
" result.add(element)\n"
|
||||
" }\n"
|
||||
" return result\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"class String is Sequence {\n"
|
||||
|
||||
11
test/core/sequence/list.wren
Normal file
11
test/core/sequence/list.wren
Normal file
@ -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