Referencing a function
suggest changeFunctions are first-class citizens in Kotlin. You can obtain a reference on it using double colons and then pass it to another function:
fun isPositive(x: Int) = x > 0
val numbers = listOf(-2, -1, 0, 1, 2)
println(numbers.filter(::isPositive)) // [1, 2]
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents