Arithmetic operators

In this section, you will find the information about the numeric operators.

What are they?

OperatorsExampleAction
sumsum(constant(1), constant(2))Sum operator for elements Int and Double.
subtractsubtract(constant(2), constant(1))Subtraction operator for elements Int and Double.
multiplymultiply(constant(2), constant(2))Multiplication operator for elements Int and Double.
dividedivide(constant(10.0), constant(2.0))Division operator for elements Int and Double.

Example

The example below is a simples counter, where:

  • Two buttons increment and decrement, has SetContext action.
  • The context value that has the id counter is modified with the operations addition and subtraction, it increments and decreases the value of 1 to a text value, see below:
fun screen() = Screen(
    navigationBar = NavigationBar(
        title = "Operations",
        showBackButton = true
    ),
    child = Container(
        context = ContextData("counter", 2),
        children = listOf(
            Text(constant("Sum of 2 + 1 = ").plus(sum(constant(2), constant(1)).toBindString())),
            Text(expressionOf("Counter: @{counter}")),
                Container(
                    children = listOf(
                        Button(
                            text = "increment",
                            onPress = listOf(
                                SetContext("counter", "@{sum(counter, 1)}")
                            )
                        ),
                        Button(
                            text = "decrement",
                            onPress = listOf(
                                SetContext("counter", "@{subtract(counter, 1)}")
                            )
                        )
                    )
                )
            )
        )
    )
}