[Pkg] The Trunk: Collections-eem.473.mcz

commits at source.squeak.org commits at source.squeak.org
Sun Apr 29 00:03:28 UTC 2012


Eliot Miranda uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-eem.473.mcz

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

Name: Collections-eem.473
Author: eem
Time: 28 April 2012, 5:02:56.235 pm
UUID: 6fa8cab9-1079-4bba-9fe4-0a96fcd47256
Ancestors: Collections-eem.472

A reimplementation of Travis Griggs' piecesCutWhere:[do:]

=============== Diff against Collections-eem.472 ===============

Item was added:
+ ----- Method: SequenceableCollection>>piecesCutWhere: (in category 'enumerating') -----
+ piecesCutWhere: binaryBlock
+ 	"Answer substrings of the receiver derived from cutting the receiver
+ 	 at points where binaryBlock answers true for adjacent elements."
+ 
+ 	| pieces |
+ 	pieces := OrderedCollection new.
+ 	self piecesCutWhere: binaryBlock
+ 		do: [:piece|
+ 			pieces add: piece].
+ 	^pieces
+ 
+ 	"'Now is the time for all good people to come to the aid of the cause of world peace.  It is just fine, even desirable, to love your country, if that means wanting it to play a beneficial role in the course of world events and be the best possible example of a good society.  But if it means wanting dominion over the rest of the world, it is not love but defensiveness or self-glorification, and will lead only to oblivion.'
+ 		piecesCutWhere: [:a :b| a = $. and: [b isSeparator]]"!

Item was added:
+ ----- Method: SequenceableCollection>>piecesCutWhere:do: (in category 'enumerating') -----
+ piecesCutWhere: binaryBlock do: pieceBlock
+ 	"Evaluate pieceBlock with substrings of the receiver derived from cutting the
+ 	 receiver at points where binaryBlock answers true for adjacent elements."
+ 
+ 	| size lastCut this next |
+ 	(size := self size) <= 1 ifTrue:
+ 		[size = 1 ifTrue:
+ 			[pieceBlock value: self].
+ 		 ^self].
+ 	lastCut := 1.
+ 	this := self at: 1.
+ 	2 to: size do:
+ 		[:i|
+ 		next := self at: i.
+ 		(binaryBlock value: this value: next) ifTrue:
+ 			[pieceBlock value: (self copyFrom: lastCut to: i - 1).
+ 			lastCut := i].
+ 		this := next].
+ 	pieceBlock value: (self copyFrom: lastCut to: size)!



More information about the Packages mailing list