On Thu, Jul 16, 2009 at 5:04 PM, Lukas Renggli<renggli@gmail.com> wrote:
  ((aCollection readStream     select: [ :e | ... ])     collect: [ :e | ... ])     contents
will iterate only once. Furthermore the second approach allows any combination of any of the enumeration methods, not just a few predefined ones. Also the implementation is less error prone, because it just uses the standard methods on collection and stream.
This is what I did in Nile: NSCollectionStream>>select: aBlock "Returns a new stream which contains a selection of elements in the receiver. All elements of the receiver are passed to aBlock. This is really like Collection>>select:." ^ NSSelectStream selectBlock: aBlock inputStream: self NSSelectStream being a kind of stream whose #next method iterate on the input stream: NSSelectStream>>next self inputStream do: [:each | (selectBlock value: each) ifTrue: [^ each]]. -- Damien Cassou http://damiencassou.seasidehosting.st "Lambdas are relegated to relative obscurity until Java makes them popular by not having them." James Iry