On Sat, Dec 26, 2009 at 11:44 PM, Julian Fitzell <[email protected]> wrote:

> Personally, I would rather see #ifEmpty: modified to return self in
> the false case like #ifNil: does. The only in-image sender I can find
> that even uses the return value seems to actually expect this
> behaviour anyway. :)
>
>
Julian: we (stef and I) have something we don't understand. The
implementation of ifEmpty: is like this in Pharo:

Collection >> ifEmpty: aBlock
    "Evaluate the block if I'm empty"

    self isEmpty ifTrue: [ ^aBlock value ]


In this case, in the false case, nothing is expressively returned, so self
is returned.

Did I miss something ?

cheers

mariano


> Then you could simply write:
>
> (aCollection select: [:ea | ...]) ifEmpty: [ ... ]
>
> Julian
>
> 2009/12/26 Bart Gauquie <[email protected]>:
> > Dear all,
> >
> > While developing some code, I made following extension of the Collection
> > protocol:
> > select: aBlock ifNoneTakeAsDefault: aDefaultValue
> >    |result|
> >    result := self select: aBlock.
> >    (result isEmpty)
> >       ifTrue: [^self class with: aDefaultValue]
> >       ifFalse: [^result].
> >
> > Maybe this could be added to the Pharo 1.1 Collection clazz? Or do we
> want
> > to keep the interface of Collection as small as possible (which is also a
> > good idea!).
> > Kind Regards,
> > Bart
> > --
> > imagination is more important than knowledge - Albert Einstein
> > Logic will get you from A to B. Imagination will take you everywhere -
> > Albert Einstein
> > Learn from yesterday, live for today, hope for tomorrow. The important
> thing
> > is not to stop questioning. - Albert Einstein
> > The true sign of intelligence is not knowledge but imagination. - Albert
> > Einstein
> > Gravitation is not responsible for people falling in love. - Albert
> Einstein
> >
> > _______________________________________________
> > Pharo-project mailing list
> > [email protected]
> > http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
> >
>
> _______________________________________________
> Pharo-project mailing list
> [email protected]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>
_______________________________________________
Pharo-project mailing list
[email protected]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

Reply via email to