October 2019
Intermediate to advanced
434 pages
11h 54m
English
Now that we've reviewed working with functional types, let's take a look at how to use those functional types as arguments to other functions.
Here's a basic example of a higher-order function in which we've defined a function parameter matching the function signature of our previously defined onClickHandler variable:
class ViewModel(val viewState: ViewState, val clickHandler:(ViewState) -> Unit)fun createViewModel(viewState: ViewState, clickHandler: (ViewState) -> Unit) : ViewModel { return ViewModel(viewState, clickHandler)}
We could then pass our onClickHandler function variable as an argument to this newly defined createViewModel() function:
fun main() { ... createViewModel(viewState, onClickHandler)}
As with any ...
Read now
Unlock full access