Arithmetic operator

Here you will find the complete description of arithmetic operator.

What are they?

OperatorExampleAction
sum“@{sum(3,3)}”Addition operator for the elements type Int and Double.
subtract“@{subtract(4,3)}”Subtraction operator for the elements type Int and Double.
multiply“@{multiply(3,3)}”Multiplication operator for the elements type Int and Double.
divide“@{divide(3,3)}”Division operator for the elements type Int and Double.

Example

See an example below of a counter where two buttons increment and decrement, both with SetContext actions that modifies the context value that has an id counter, altering the value with addition and subtraction operations, increasing or decresing the value of 1 to the text value:

fun screen() = Screen(
    navigationBar = NavigationBar(
        title = "Operations",
        showBackButton = true
    ),
    child = Container(
        context = ContextData("counter", 2),
        children = listOf(
            Text(expressionOf("Sum of 2 + 1 = @{sum(2, 1)}")),
            Text(expressionOf("Counter: @{counter}")),
            Button(
                text = "increment",
                onPress = listOf(
                    SetContext("counter", "@{sum(counter, 1)}"))
            ),
            Button(
                text = "decrement",
                onPress = listOf(
                    SetContext("counter", "@{subtract(counter, 1)}"))
            )
        )
    )
)