5.times.collect { f }
(Assuming no parameters. map is an alias of collect ; I prefer the name collect when I actually collect, as it seems more communicative, but YMMV.)
I also prefer a longer 5.times instead of (1..5) . It also seems more communicative: I don't really βrepeat in range,β I βdo something five times.β
The IMO answer is slightly counterintuitive in this case, since I do not execute collect five times, but collect.5.times { f } does not work, so we still play a mental game.
source share