[squeak-dev] The Inbox: Collections-mt.852.mcz
David T. Lewis
lewis at mail.msen.com
Thu Nov 21 03:35:45 UTC 2019
On Wed, Nov 20, 2019 at 08:48:50AM +0100, Marcel Taeumel wrote:
> Hi, all.
> What's the "most idiomatic" way to create an array with 100 random numbers > 0 < 100?
> (1 to: 100) collect: [:ea | 100 atRandom]
> Array streamContents: [:s | 100 timesRepeat: [s nextPut: 100 atRandom]].
If "most idiomatic" means "functionally correct, easy to read, and easy to understand"
then I prefer the first:
(1 to: 100) collect: [:ea | 100 atRandom]
I can read it from left to right, and it tells me that I am collecting
100 elements and putting 100 atRandom into each of the 100 elements.
It's also simple, just a collect: and nothing more.
More information about the Squeak-dev