[squeak-dev] Boolean whenTrue:whenFalse:

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Tue May 14 14:23:34 UTC 2019


Hi,
>From time to time, I need to perform some additional action (side effect)
when a boolean is true, but preserve that boolean as return value.

Here is a pseudo example:

    self findLast: [:each |
        | conforming |
        conforming := self testSomeConditionFor: each.
        conforming
            ifTrue:
                [ "found one, do some side effect before searching next"
                self performSomeAction: each ].
         conforming ].

Or shorter, but I dislike the redundant true:

    self findLast: [:each |
        (self testSomeConditionFor: each)
            and:
                [ "found one, do some side effect before searching next"
                self performSomeAction: each.
                true ]].

What i seek is even shorter:

    self findLast: [:each |
        (self testSomeConditionFor: each)
            whenTrue:
                [ "found one, do some side effect before searching next"
                self performSomeAction: each ]].

Of course, we would have companions whenFalse:, whenTrue:whenFalse:...
Would you buy it?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20190514/28234646/attachment.html>


More information about the Squeak-dev mailing list