tudor at tudorgirba.com
Fri Nov 1 18:55:02 EDT 2013
I see that Pharo 3.0 has a Collection>>flatCollect:. This is great as the
method proved to be very valuable in the context of Moose.
However, the current Pharo implementation is less ideal:
^ Array streamContents:
self do: [:ea | stream nextPutAll: (aBlock value: ea)]]
The Moose one is:
"Evaluate aBlock for each of the receiver's elements and answer the
list of all resulting values flatten one level. Assumes that aBlock returns
of collection for each element. Equivalent to the lisp's mapcan"
"original written by a. Kuhn and released under MIT"
| stream |
self isEmpty ifTrue: [ ^ self copy ].
stream := (self species new: 0) writeStream.
self do: [ :each | stream nextPutAll: (aBlock value: each) ].
^ stream contents
The difference is in the type returned. The Pharo one always returns Array,
while the Moose one returns a collection of the same species as the
Does anyone have anything against the Moose implementation?
"Every thing has its own flow"
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Pharo-dev