Array Operation

Operation description to manipulate Arrays.

Which are they?

OperatorsExampleAction
insert“@{insert(array, 5)}”Inserts an element into the array. This operator takes two parameters, the first is an array and the second is the element that you want to insert into this array.
remove“@{remove(array, 1)}”Removes an element from an array. This operator takes two parameters, the first is an array and the second is the element that you want to remove from this array.
removeIndex“@{removeIndex(array, 2)}”Removes an element from an array according to the element’s position. This operator takes two parameters, the first is an array and the second is the index of the element you want to remove from this array.
contains“@{contains(array, 3)}”Checks whether the array contains an element. This operator takes two parameters, the first is an array and the second is the element that you want to check

Example

The example below modifies an array that was defined in the Context with id numbersArray and value [0, 1, 2, 3, 4] .

fun screen() = Screen(child = 
    Container(
        context = ContextData(id = "numbersArray", value = arrayOf(0,1,2,3,4)),
        children = listOf(
            Text(text = "Array was [0, 1, 2, 3, 4] and after removing index 2 now is: "),
            Text(
                expressionOf("@{removeIndex(numbersArray, 2)}")
            ).setStyle{ backgroundColor = constant("#00FF00") }
        )
    )
)