(Int) -> ((Int) -> Unit)
is a method that, given an Int
, produces (Int) -> Unit
, a function that, given an Int
, gives Unit
. It would be used like this, with type specifications for clarity:
fun example(lambda1: (Int) -> ((Int) -> Unit)) {
val lambda2: (Int) -> Unit = lambda1.invoke(5)
lambda2.invoke(7)
Meanwhile, ((Int) -> (Int)) -> Unit
is a method that takes as an argument an (Int) -> Int
, and returns Unit
. An example might be a mutation on a boxed value:
data class Box(var value: Int) {
fun mutate(mutation: ((Int) -> Int) -> Unit) {
value = mutation(value)
}
}