🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators whentrue
(Automatically adding template at the end of the page.)
(Adding message template to the top of the page)
Line 1: Line 1:
{{message|Write the content here to display this box}}
When you have an immutable OCLexpression, you always return a value - and then the [[OCLOperators casetruefalse|OCLOperators_caseTrueFalse]] is good - but when using the MDriven Action-Language that allows updates of objects, another construct is introduced to compact things even more:
When you have an immutable OCLexpression, you always return a value - and then the [[OCLOperators casetruefalse|OCLOperators_caseTrueFalse]] is good - but when using the MDriven Action-Language that allows updates of objects, another construct is introduced to compact things even more:



Revision as of 22:26, 16 June 2024

This page was created by Hans.karlsen on 2021-12-04. Last edited by Stephanie on 2025-02-11.

Write the content here to display this box

When you have an immutable OCLexpression, you always return a value - and then the OCLOperators_caseTrueFalse is good - but when using the MDriven Action-Language that allows updates of objects, another construct is introduced to compact things even more:

boolean.whentrue(dothis):boolean

The return is always the arg0

Example:

let x=SomeObject.SomeEnum in (  
  (x=#Enum1).whentrue(SomeObject.DoYourThing1);  
  (x=#Enum2).whentrue(SomeObject.DoYourThing2);  
  (x=#Enum3).whentrue(SomeObject.DoYourThing3) 
)

Fun fact: "whentrue" and logical "and" are implemented the same - the logical "and" only evaluates arg1 of arg0 is true (lazy evaluation) and "whentrue" does the same thing, but always returns arg0.

This means that a convoluted but equivalent construct can be:

let x=SomeObject.SomeEnum in (  
  (x=#Enum1) and (SomeObject.DoYourThing1;true);  
  (x=#Enum2) and (SomeObject.DoYourThing2;true);  
  (x=#Enum3) and (SomeObject.DoYourThing3;true) 
)
MDriven Chat

How would you like to chat today?

Setting up your conversation…

This may take a few moments