Hi Simon,
As you and Doru pointed out, in VW you get #(1 3) and in Pharo #(1 3
nil nil).
I am not sure which result is the less surprising.
The result of '#((1) (3) () ()) collect: [:each ]' contains nil as
well.
An elegant solution to remove nil value, is simply to use 'reject:
#isNil'
(#((1) (3) () ()) flatCollect: [ :each ]) reject: #isNil
Cheers,
Alexandre
On 30 Mar 2009, at 18:03, Simon Denier wrote:
I ran into the following problem (related to
FamixModelExtractionTest even if it's more general)
(#((1) (3) () ()) flatCollect: [ :each ])
returns
#(1 3 nil nil)
when one expects #(1 3)
flatCollect: is defined in Colllection, I dont want to override it
if possible.
Collection>>flatCollect: aBlock
| stream |
self isEmpty ifTrue: [ ^ self copy ].
stream := (self species new: self size) nsWriteStream.
self do: [ :each | stream nextPutAll: (aBlock value: each) ].
^ stream contents
Can someone find an elegant solution which would "shrink" the
resulting array to its non-nil content?
--
Simon
_______________________________________________
Moose-dev mailing list
Moose-dev(a)iam.unibe.ch
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
--
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel
http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.