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

commits at source.squeak.org commits at source.squeak.org
Wed Apr 14 12:38:22 UTC 2021


A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-mt.938.mcz

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

Name: Collections-mt.938
Author: mt
Time: 14 April 2021, 2:38:21.265628 pm
UUID: d109bde4-42a6-e840-803c-e4e80b98a74d
Ancestors: Collections-mt.937

Proposal. Add a #joinSeparatedBy: that does not end up as a string.

The current alternative would be #gather
(#(1 2 3 4 5) gather: [:each | {each . $x}]) allButLast.

Not sure whether a non-sequenceable version in Collection makes sense. We have had that discussion about #join etc. being not useful for uncertain output order.

Some benchmarks:

[ ((1 to: 1000) gather: [:num | {num . $x}]) allButLast ] bench.
'22,000 per second. 45.5 microseconds per run. 13.09738 % GC time.'

[ (1 to: 1000) collect: [:num | num] separatedBy: [$x] ] bench.
'26,000 per second. 38.5 microseconds per run. 1.73965 % GC time.'

=============== Diff against Collections-mt.937 ===============

Item was added:
+ ----- Method: Collection>>collect:separatedBy: (in category 'enumerating') -----
+ collect: elementBlock separatedBy: separatorBlock
+ 	"Evaluate the elementBlock for all elements in the receiver, and evaluate the separatorBlock between. Collect the resulting values of both blocks into a collection like the receiver. Answer the new collection."
+ 
+ 	| newCollection |
+ 	newCollection := self species new.
+ 	self
+ 		do: [:each | newCollection add: (elementBlock value: each)]
+ 		separatedBy: [:each | newCollection add: separatorBlock value].
+ 	^ newCollection!

Item was added:
+ ----- Method: SequenceableCollection>>collect:separatedBy: (in category 'enumerating') -----
+ collect: elementBlock separatedBy: separatorBlock
+ 	"Evaluate the elementBlock for all elements in the receiver, and evaluate the separatorBlock between. Collect the resulting values of both blocks into a collection like the receiver. Answer the new collection."
+ 
+ 	| newCollection |
+ 	newCollection := self species new: self size *2 -1.
+ 	1 to: self size do: [:index |
+ 		index = 1 ifFalse: [newCollection at: (index-1 *2) put: separatorBlock value].
+ 		newCollection at: (index-1 *2)+1 put: (elementBlock value: (self at: index))].
+ 	^ newCollection!



More information about the Squeak-dev mailing list