August 2017
Intermediate to advanced
440 pages
10h
English
In Kotlin, higher-order functions are really important, and so it is also important to make their usage as easy as possible. This is why Kotlin introduced a special convention that makes higher-order functions simpler and clearer. It works this way: if the last parameter is a function, then we can define a lambda expression outside of the brackets. Let's see how it looks if we use it with the longOperationAsync function, which is defined as follows:
fun longOperationAsync(a: Int, callback: ()->Unit) {
// ...
}
The function type is in the last position in the arguments. This is why we can execute it this way:
longOperationAsync(10) {
hideProgress()
}
Thanks to the last lambda in an argument convention, ...
Read now
Unlock full access