Is this what you had in mind?
collect: aBlock until:quitBlock
"Evaluate aBlock with each of the receiver's elements as the
argument.
Stop when quitBlock evaluates to true.
Collect the resulting values into a collection like the
receiver. Answer
the new collection."
| newCollection |
newCollection := self species new.
self do: [:each |
( quitBlock value:each )
ifFalse:[
newCollection add: (aBlock value: each)
]
ifTrue:[
^newCollection.
].
].
^ newCollection.
You might first look at #select:thenCollect: to see if it meets your
needs. The "until" is a little stream-like, so you might also consider
moving items from a read stream to a write stream on a new collection
and then collect from it.
Bill
Wilhelm K. Schwab, Ph.D.
University of Florida
Department of Anesthesiology
PO Box 100254
Gainesville, FL 32610-0254
Email:
[hidden email]
Tel: (352) 846-1285
FAX: (352) 392-7029