<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>