Accumulates a current value by evaluating expression.
intoInject(Block expression,Object startValue) | |||
---|---|---|---|
Arguments | Block | expression | Expression that should be applied to all objects in the collection. |
Object | startValue | Start value of the accumulation. | |
Return value | Object | Result of the accumulation |
Formula | Result |
---|---|
=List{ 10, 11, 12}.intoInject(r,accu | r + accu,0) | 33 |
=List{'String1','String2','String3'}.intoInject(r,accu | accu.append(Pair{r,r + '_Value'}),List{}) | [String1»String1_Value,String2»String2_Value,String3»String3_Value] |
Description for the example 1:
Data in this example
- List{10,11,12} = List of objects iterated over with intoInject
- r = Index variable
- accu = Variable for the intermediate value
- r + accu = Instruction (any EEC formula is possible)
- 0 = Starting value for accu
Index number of iteration | Index variable r | Intermediate value accu | Result value for r + accu |
---|---|---|---|
1 | 10 | 0 | 10 |
2 | 11 | 10 | 21 |
3 | 12 | 11 | 33 |
intoInject is used in practice, e.g., to apply Maps whose key-value pairs contain lists as values.
The following example shows how signal names are collected in a project and sorted in a map depending on their signal type.
The following signal types are available in the data model:
- AbsSignal.AbsActuator.AO
- AbsSignal.AbsActuator.DO
- AbsSignal.AbsSensor.AI
- AbsSignal.AbsSensor.DI
The following formula collects the signal names of the whole model:
=rmos('ModularSystem.Controller.Signals.AbsSignal').intoInject(signal,map| // check if signal is already in map
if map.containsKey(signal.SignalType)then // if yes, then add the signal to the list
map.add(signal.$SignalType,map.value(signal.$SignalType).append(signal))
else // if not, then add the signal to the map (creates new list)
map.add(signal.$SignalType,List{signal})
endif
,Map{})
The result looks like follows:
[DO»[<<DO>>,<<DO>>],AI»[<<AI>>],DI»[<<DI_1>>,<<DI_2>>,<<DI>>]]
A map with three key-value pairs was formed in which the key is always the signal type and the value is always a list of signals of the signal type.