问题
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?
回答1:
+
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" }
来源:https://stackoverflow.com/questions/58571670/whats-the-meaning-of-plus-sign-before-a-kotlin-method