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?
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.
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.
The plus sign (+) is a string concatenation operator that permits us to thread together literals and variables into a single string.
:: is used for Reflection in kotlin. Class Reference val myClass = MyClass::class. Function Reference this::isEmpty.
+
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" }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With