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

Levente Uzonyi leves at caesar.elte.hu
Tue Nov 19 10:39:02 UTC 2019


On Mon, 18 Nov 2019, Marcel Taeumel wrote:

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

#fillFrom:with: is a private method which exists to support #collect:as: 
and #collect:into:.
I just noticed that there's a third user: #any:as:.

Levente

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


More information about the Squeak-dev mailing list