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

commits at source.squeak.org commits at source.squeak.org
Fri Sep 6 14:57:46 UTC 2019


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!



More information about the Squeak-dev mailing list