[squeak-dev] The Inbox: Collections-mt.852.mcz

Marcel Taeumel marcel.taeumel at hpi.de
Mon Nov 18 14:00:34 UTC 2019


Hi, all.

Any thoughts on this matter? Here are more examples:

OrderedCollection new: 20 filledWith: [100 atRandom].
Set new: 20 filledWith: [:ea | (ea + 32) asCharacter].
Dictionary new: 20 filledWith: [:ea | ea -> (ea + 32) asCharacter].

Further reading (for related naming and concepts):

(all implementors of ...)
#collect:as:
#fillFrom:with:
#newFrom:
#new:withAll:

Best,
Marcel
Am 06.09.2019 16:57:53 schrieb commits at source.squeak.org <commits at source.squeak.org>:
A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-mt.852.mcz

==================== Summary ====================

Name: Collections-mt.852
Author: mt
Time: 6 September 2019, 4:57:45.245608 pm
UUID: 3582be1c-a006-ed46-a517-3d2d570db6cc
Ancestors: Collections-mt.851

Proposal: Initialize a new collection with a computation block without needing an existing collection to #collect: from.

OrderedCollection new: 20 filledWith: [100 atRandom].

Thanks to Christoph (ct) for the idea.

If we want this in Trunk, there will be tests. :-)

=============== Diff against Collections-mt.851 ===============

Item was added:
+ ----- Method: ArrayedCollection class>>new:filledWith: (in category 'instance creation') -----
+ new: size filledWith: aBlock
+ "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."
+
+ | result |
+ result := self new: size.
+ 1 to: size do: [:each | result at: each put: (aBlock cull: each)].
+ ^ result!

Item was added:
+ ----- Method: Collection class>>new:filledWith: (in category 'instance creation') -----
+ new: size filledWith: aBlock
+ "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."
+
+ | result |
+ result := self new: size.
+ 1 to: size do: [:each | result add: (aBlock cull: each)].
+ ^ result!


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20191118/a8e9bd27/attachment.html>


More information about the Squeak-dev mailing list