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

Tobias Pape Das.Linux at gmx.de
Mon Nov 18 14:07:03 UTC 2019


> On 18.11.2019, at 15:00, Marcel Taeumel <marcel.taeumel at hpi.de> 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:
> 

Here's an example from the scheme/lisp world how they're using that:

https://docs.racket-lang.org/reference/pairs.html?q=make-list#%28def._%28%28lib._racket%2Fprivate%2Flist..rkt%29._build-list%29%29

> 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