This function increases the value under key a in map c by b. Each call accumulates the result. The function keeps the previous value and adds b on top. NOTE If the initial value is not numeric, the function converts it to 0. If key a does not exist yet, the function initializes it with 0 as well.
The function returns the value of b as BigDecimal. This applies even when the function did not actually add b. See parameter d for details.
Typical use case: Build counters or sums across multiple iterations. For example, collect total quantities or position sums from repeated calls.
Parameters
Parameter | Description |
|---|---|
a | Key of the value. |
b | The value to add. |
c | (optional) Name of the map. Default: default. |
d | (optional) If true, the function ignores b when its Empty Flag is set. Default: false. |
Note
The Empty Flag is an internal property of a value in Lobster. It marks a value as "empty". This also applies when the value formally has content. An example is an empty string. Parameter d controls whether such values are included in the addition.
Example
Read the example entries as sequential calls. The value under key mykey in map mymap is initially 0.
Parameter a | Parameter b | Parameter b empty? | Parameter c | Parameter d | Result | Value in map |
|---|---|---|---|---|---|---|
mykey | 123 | No | mymap | 123 | 123 | |
mykey | 123 | No | mymap | 123 | 246 | |
mykey | 123 | Yes | mymap | 123 | 369 | |
mykey | 123 | Yes | mymap | false | 123 | 492 |
mykey | 123 | Yes | mymap | true | 123 | 492 |
NOTE If d = true and the Empty Flag is set, the function does not add b. The map value stays unchanged at 492. The function still returns b as BigDecimal (value 123).