[Pharo-dev] flatCollect:

Sebastian Tleye stleye at gmail.com
Fri Nov 1 19:49:28 EDT 2013


Hi,

flatCollect: is called by Collection>>gather:
instead of renaming gather: what we did is add "flatCollect:" to keep
compatibility. Take into account that if you change what flatCollect:
returns it will affect all the methods that use "gather:"


2013/11/1 Gabriel Cotelli <g.cotelli at gmail.com>

> I don't have a Pharo at hand now,but if species returns the class of the
> collection, be carefull with SortedCollection because in that case the
> sortBlock could not work with the collected objects.
>
>
> On Fri, Nov 1, 2013 at 7:55 PM, Tudor Girba <tudor at tudorgirba.com> wrote:
>
>> Hi,
>>
>> 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:
>>
>> Collection>>flatCollect: aBlock
>> ^ Array streamContents:
>> [:stream |
>>  self do: [:ea | stream nextPutAll: (aBlock value: ea)]]
>>
>> The Moose one is:
>> Collection>>flatCollect: aBlock
>>  "Evaluate aBlock for each of the receiver's elements and answer the
>> list of all resulting values flatten one level. Assumes that aBlock
>> returns some kind
>>  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
>> receiver.
>>
>> Does anyone have anything against the Moose implementation?
>>
>> Doru
>>
>> --
>> www.tudorgirba.com
>>
>> "Every thing has its own flow"
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20131101/453aa943/attachment-0002.html>


More information about the Pharo-dev mailing list