“You can assign this function to a variable using the method reference operator, ::, like so:
var function = ::add
Here, the name of the variable is function and its type is inferred as (Int, Int) → Int from the add function you assigned to it. The function variable is of a function type that takes two Int parameters and returns an Int.”
Excerpt From: By Joe Howard. “Kotlin Apprentice.” Apple Books.
(Int, Int) -> Int
looks like Swift to me. Could we get an explanation of why ->
is used in Kotlin when passing a function as a parameter, but :
is used for the return type of a function; whereas in Swift ->
is used throughout? Note we are previously introduced to ->
in the previous chapter with the when
statement