OCLOperators whentrue
No edit summary
No edit summary
Line 2: Line 2:


boolean.case(dothis):boolean
boolean.case(dothis):boolean
The return is always the arg0


Example:
Example:
Line 8: Line 10:
   (x=#Enum2).case(SomeObject.DoYourThing2);  
   (x=#Enum2).case(SomeObject.DoYourThing2);  
   (x=#Enum3).case(SomeObject.DoYourThing3)  
   (x=#Enum3).case(SomeObject.DoYourThing3)  
)
Fun fact: "case" and logical "and" are implemented the same - the logical "and" only evaluates arg1 of arg0 is true (lazy evaluation) and "case" 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)
  )
  )

Revision as of 10:22, 4 December 2021

When having immutable ocl expression you always return a value - and the the OCLOperators_TrueFalse is good, but when using the MDriven Action-Language that allows updates of objects another construct is introduced to compact things even more:

boolean.case(dothis):boolean

The return is always the arg0

Example:

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

Fun fact: "case" and logical "and" are implemented the same - the logical "and" only evaluates arg1 of arg0 is true (lazy evaluation) and "case" 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) 
)
This page was edited 96 days ago on 02/10/2024. What links here