This website requires JavaScript.
Explore
Mail
Help
Register
Sign In
Meson
/
wren
Watch
1
Star
0
Fork
0
You've already forked wren
forked from
Mirror/wren
Code
Pull Requests
Activity
Files
563a0908658e163a85e793b4f7db881ea0084466
wren
/
test
/
core
/
list
/
map.wren
4 lines
83 B
Plaintext
Raw
Normal View
History
Unescape
Escape
Cleanups for merging map method
2014-02-15 00:34:30 -06:00
var a = [1, 2, 3]
Use deferred execution for Sequence.map and Sequence.where The methods Sequence.map and Sequence.where are now implemented using deferred execution. They return an instance of a new Sequence-derived class that performs the operation while iterating. This has three main advantages: * It can be computationally cheaper when not the whole sequence is iterated. * It consumes less memory since it does not store the result in a newly allocated list. * They can work on infinite sequences. Some disadvantages are: * Iterating the returned iterator will be slightly slower due to the added indirection. * You should be aware that modifications made to the original sequence will affect the returned sequence. * If you need the result in a list, you now need to call Sequence.list on the result.
2015-03-28 22:51:50 +01:00
var b = a.map {|x| x + 1 }.list
Cleanups for merging map method
2014-02-15 00:34:30 -06:00
IO.print(b) // expect: [2, 3, 4]
Copy Permalink