Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the meaning of plus sign before a Kotlin method?

I'm studiyng Kotlin and was watching the AndroidDevSummit, more specifically the presentation "Undestanding Compose" from Leland Richardson.

While the presentation (at 28min26sec), he shown the following code:

@Composable
fun App(items: List<String>, query: String) {
    val results = +memo(items, query) {
        items.filter { it.matches(query) }
    }
    // ...
}

What does the "+" plus sign before the "memo" method?

like image 343
Jose Silva Avatar asked Oct 26 '19 14:10

Jose Silva


People also ask

What is plus in Kotlin?

In Kotlin, plus ( + ) and minus ( - ) operators are defined for collections. They take a collection as the first operand; the second operand can be either an element or another collection.

What is the plus (+) sign used to do in Java?

A - The plus sign (+) is automatically overloaded in Java. The plus sign can be used to perform arithmetic addition. It can also be used to concatenate strings. However, the plus sign does more than concatenate strings.

What data type is plus sign?

The plus sign (+) is a string concatenation operator that permits us to thread together literals and variables into a single string.

What is :: operator in Kotlin?

:: is used for Reflection in kotlin. Class Reference val myClass = MyClass::class. Function Reference this::isEmpty.


1 Answers

+ is kind of like an operator invoke for effects. The functions that return effects just return an object for the effect and the + says, "add it into the composition here"

by Adam Powell on Kotlin Slack

The full thread on kotlin slack

The + operator will be removed in the future, for states, probably will use Property Delegates, something like this: var myState by state { "value" }

like image 173
DevSrSouza Avatar answered Nov 16 '22 02:11

DevSrSouza