[squeak-dev] Boolean whenTrue:whenFalse:

Torge Husfeldt torge.husfeldt at gmx.de
Thu May 16 14:51:58 UTC 2019


Salut Nico,

please excuse if my squeak knowlege is a bit rusty, but wouldn't this do
the job:

self findlast: [:each |

[self testSomeConditionFor: each] value ifTrue:[self
performSomeAction:each]; yourself.

].

Just an idea. And very sad that I have to wrap the condition in a block,
but I guess othewise the recipient for "yourself" would be "self"

On 14.05.19 17:02, Nicolas Cellier wrote:
> Oups, my example was a bit stupid because findLast: loop stops at
> first true, but you get my intention...
> Replace with select:/reject: or provide a whenFalse: side effect...
>
> Le mar. 14 mai 2019 à 16:23, Nicolas Cellier
> <nicolas.cellier.aka.nice at gmail.com
> <mailto:nicolas.cellier.aka.nice at gmail.com>> a écrit :
>
>     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/20190516/4dbc05c7/attachment.html>


More information about the Squeak-dev mailing list