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

commits at source.squeak.org commits at source.squeak.org
Thu May 9 13:27:07 UTC 2019


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

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

Name: Collections-mt.832
Author: mt
Time: 9 May 2019, 3:27:06.069782 pm
UUID: b3c087f4-c2bc-d542-91d7-9c214ae3a97f
Ancestors: Collections-nice.831

Adds #take: to create a sub-collection from any collection by specifying the number of elements. Works like #first: for sequenceable collections but does not fail if collection is too small.

=============== Diff against Collections-nice.831 ===============

Item was added:
+ ----- Method: CharacterSet>>take: (in category 'accessing') -----
+ take: n
+ 
+ 	self shouldNotImplement.!

Item was added:
+ ----- Method: Collection>>take: (in category 'accessing') -----
+ take: n
+ 	"Enumerate this collection and return the first n elements or less."
+ 
+ 	| index result |
+ 	index := 1.	
+ 	result := self species new: (n min: self size).
+ 	self associationsDo: [:each | 
+ 		result add: each.
+ 		(index := index + 1) > n ifTrue: [^ result]].
+ 	^ result!

Item was added:
+ ----- Method: SequenceableCollection>>take: (in category 'accessing') -----
+ take: n
+ 
+ 	^ self first: (n min: self size)!

Item was added:
+ ----- Method: Stream>>take: (in category 'accessing') -----
+ take: n
+ 
+ 	^ self next: n!



More information about the Squeak-dev mailing list