<div dir="ltr"><div>Hi,</div><div>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.</div><div><br></div><div>Here is a pseudo example:<br></div><div><br></div><div> self findLast: [:each |</div><div> | conforming |<br></div><div>
conforming
:= self testSomeConditionFor: each.</div><div>
conforming <br></div><div> ifTrue:</div><div> [
"found one, do some side effect before searching next" <br></div><div> self performSomeAction: each ].<br></div><div>
conforming
].</div><div><br></div><div>Or shorter, but I dislike the redundant true:
<div><br></div><div> self findLast: [:each |</div><div> (self testSomeConditionFor: each)</div><div> and:</div><div> [
"found one, do some side effect before searching next" <br></div><div> self performSomeAction: each.</div><div> true ]].</div><div><br></div><div>What i seek is even shorter:
<div><br></div><div> self findLast: [:each |</div><div> (self testSomeConditionFor: each)</div><div> whenTrue:</div><div> [
"found one, do some side effect before searching next" <br></div><div> self performSomeAction: each ]].</div><div><br></div><div>Of course, we would have companions whenFalse:, whenTrue:whenFalse:...<br></div><div>Would you buy it?<br></div><div><br></div><div><br></div>
</div>
</div></div>