RCR: Accumulating block

M

Martin DeMello

A bit of a wild idea, but how about syntactic support for accumulating
the results of multiple calls to yield?

a = []
(1..10).step(2) {|i|
...
a << retval
}

could become

a = (1..10).step(2) [|i| ...]

martin
 
N

nobu.nokada

Hi,

At Sun, 25 Apr 2004 03:04:04 +0900,
Martin DeMello wrote in [ruby-talk:98258]:
A bit of a wild idea, but how about syntactic support for accumulating
the results of multiple calls to yield?

a = []
(1..10).step(2) {|i|
...
a << retval
}

could become

a = (1..10).step(2) [|i| ...]

I don't feel it so essential.

$ ruby -renumerator -e 'p (1..10).enum_for:)step, 2).to_a
[1, 3, 5, 7, 9]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top