A new version of Kernel was added to project The Inbox:
http://source.squeak.org/inbox/Kernel-ct.1266.mcz ==================== Summary ==================== Name: Kernel-ct.1266 Author: ct Time: 6 September 2019, 1:16:39.325698 pm UUID: a5b0464f-61cf-4749-9ad3-92e7d8c85341 Ancestors: Kernel-eem.1265 Add shorthands for interval collecting There are enough senders of #timesRepeat: that manually fill a collection, same goes for #to:do: =============== Diff against Kernel-eem.1265 =============== Item was added: + ----- Method: Integer>>timesCollect: (in category 'enumerating') ----- + timesCollect: aBlock + + ^ (1 to: self) collect: [:i | aBlock value]! Item was added: + ----- Method: Number>>to:collect: (in category 'intervals') ----- + to: stop collect: aBlock + "Evaluate aBlock for each element of the interval (self to: stop by: 1) and return the results." + + ^ (self to: stop) collect: aBlock! |
Hmm... #timesCollect: seems strange. Especially since #timesRepeat: does not provide the iteration number to the block. Then, #to:collect: has a similar problem: "from x to y collect what?" The explicit from "(x to: y)" for the interval object seems more readable. -1 ;-) Best, Marcel
|
In reply to this post by commits-2
I think it is better to name the kind of collection you are going to fill. For some of these examples, there are better ways such as "OrderedCollection new: 20 withAll: 0". Maybe support blocks in #new:withAll:? OrderedCollection new: 20 withAll: [:index | index atRandom]
Best, Marcel
|
Good point. Maybe introduce a new selector, for example #new:withEach:? It might be misleading if you really want to create a collection of blocks.
OrderedCollection new: 20 withEach: [50 atRandom]
I think the block should be called with #cull:, as there are many cases where index does not matter.
Best, Christoph Von: Taeumel, Marcel
Gesendet: Freitag, 6. September 2019 16:40:59 An: Thiede, Christoph; gettimothy via Squeak-dev Betreff: Re: AW: [squeak-dev] The Inbox: Kernel-ct.1266.mcz
I think it is better to name the kind of collection you are going to fill.
For some of these examples, there are better ways such as "OrderedCollection new: 20 withAll: 0".
Maybe support blocks in #new:withAll:?
OrderedCollection
new: 20
withAll: [:index | index atRandom]
Best,
Marcel
Carpe Squeak!
|
I put a proposal in the inbox: Collections-mt.852. Best, Marcel
|
Free forum by Nabble | Edit this page |