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

时间秒杀一切 提交于 2020-01-21 04:42:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!