<body><div id="__MailbirdStyleContent" style="font-size: 10pt;font-family: Arial;color: #000000">
                                        Thanks! Still, I have to compute the numbers:<div><br></div><div>(Random new next: 100) collect: [:ea | (ea * 100) truncated]<br></div><div><br></div><div>Best,</div><div>Marcel</div><div class="mb_sig"></div><blockquote class="history_container" type="cite" style="border-left-style:solid;border-width:1px; margin-top:20px; margin-left:0px;padding-left:10px;">
                        <p style="color: #AAAAAA; margin-top: 10px;">Am 20.11.2019 08:58:13 schrieb Nicolas Cellier <nicolas.cellier.aka.nice@gmail.com>:</p><div style="font-family:Arial,Helvetica,sans-serif">
<div dir="ltr">Random new next: 100<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le mer. 20 nov. 2019 à 08:49, Marcel Taeumel <<a href="mailto:marcel.taeumel@hpi.de">marcel.taeumel@hpi.de</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div id="gmail-m_-7329702244548170194__MailbirdStyleContent" style="font-size: 10pt;font-family: Arial;color: rgb(0,0,0)">
                                        Hi, all.<div><br></div><div>What's the "most idiomatic" way to create an array with 100 random numbers > 0 < 100?</div><div><br></div><div><div>(1 to: 100) collect: [:ea | 100 atRandom]</div><div>Array streamContents: [:s | 100 timesRepeat: [s nextPut: 100 atRandom]].</div></div><div>...</div><div><br></div><div>Best,</div><div>Marcel</div><div></div><blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-top:20px;margin-left:0px;padding-left:10px">
                        <p style="color:rgb(170,170,170);margin-top:10px">Am 20.11.2019 07:08:34 schrieb Chris Muller <<a href="mailto:asqueaker@gmail.com" target="_blank">asqueaker@gmail.com</a>>:</p><div style="font-family:Arial,Helvetica,sans-serif">
<div dir="ltr"><div>On Tue, Nov 19, 2019 at 10:58 PM Chris Muller <<a href="mailto:asqueaker@gmail.com" target="_blank">asqueaker@gmail.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>They share the same selector API, but for ArrayedCollection's, it culls integers 1 to: n, while for non-Arrayed, it culls nil over and over.</div></div></blockquote><div><br></div><div>Woops, I got that wrong, sorry.  It is the index in both cases, not nil. That's better but, still, I'm sure I would just write collect:as: without remembering this.</div><div><br></div><div> - Chris</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>  This means the sender will have to know whether it's Arrayed or not anyway (otherwise you'd need a nil check inside the loop).  And so, if you have to know that, one could just write classic Smalltalk.<br></div><div><br></div><div>   (1 to: 20) collect: [ :i | ... ]</div><div><div><div><br></div><div>(with or without an "as:" converter on the end).</div><div><br></div><div>OTOH, if you were expecting a non-arrayed collection, then simply:<br></div><div><br></div><div>    Array streamContents: [ : stream | ... ] </div><div><br></div></div><div>I do appreciate the readability for people less experienced with Smalltalk, but for the long run, classic, readable, portable Smalltalk may actually be the better way for them to read it.<br></div><div><br></div><div>Collecting nil over and over could be a sign of something not fully optimized here.</div><div><br></div><div>-1 on this one, even though I'm really enjoying many of your other contributions, Christoph.<br></div><div><br></div><div>Best,</div></div><div>  Chris</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Sep 6, 2019 at 9:57 AM <<a href="mailto:commits@source.squeak.org" target="_blank">commits@source.squeak.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">A new version of Collections was added to project The Inbox:<br>
<a href="http://source.squeak.org/inbox/Collections-mt.852.mcz" rel="noreferrer" target="_blank">http://source.squeak.org/inbox/Collections-mt.852.mcz</a><br>
<br>
==================== Summary ====================<br>
<br>
Name: Collections-mt.852<br>
Author: mt<br>
Time: 6 September 2019, 4:57:45.245608 pm<br>
UUID: 3582be1c-a006-ed46-a517-3d2d570db6cc<br>
Ancestors: Collections-mt.851<br>
<br>
Proposal: Initialize a new collection with a computation block without needing an existing collection to #collect: from.<br>
<br>
OrderedCollection new: 20 filledWith: [100 atRandom].<br>
<br>
Thanks to Christoph (ct) for the idea.<br>
<br>
If we want this in Trunk, there will be tests. :-)<br>
<br>
=============== Diff against Collections-mt.851 ===============<br>
<br>
Item was added:<br>
+ ----- Method: ArrayedCollection class>>new:filledWith: (in category 'instance creation') -----<br>
+ new: size filledWith: aBlock<br>
+       "Similar to #collect:as: and #fillFrom:with: but uses only the interval (1 to: size) to fill the collection. Different compared to #new:withAll: because aBlock can return different values for each index."<br>
+ <br>
+       | result |<br>
+       result := self new: size.<br>
+       1 to: size do: [:each | result at: each put: (aBlock cull: each)].<br>
+       ^ result!<br>
<br>
Item was added:<br>
+ ----- Method: Collection class>>new:filledWith: (in category 'instance creation') -----<br>
+ new: size filledWith: aBlock<br>
+       "Similar to #collect:as: and #fillFrom:with: but uses only the interval (1 to: size) to fill the collection. Different compared to #new:withAll: because aBlock can return different values for each index."<br>
+ <br>
+       | result |<br>
+       result := self new: size.<br>
+       1 to: size do: [:each | result add: (aBlock cull: each)].<br>
+       ^ result!<br>
<br>
<br>
</blockquote></div>
</blockquote></div></div>
</div></blockquote>
                                        </div></div><br>
</blockquote></div>
</div></blockquote>
                                        </div></body>