I can define a "big" function using a "small" function:
fun apply3(a:Int, b:Int, c:Int, func: (Int,Int,Int)->Int ): Int{
return func(a,b,c)
}
I can call it so:
println(apply3(1,2,3,{a,b,c->a+b+c}))
On the other hand, if I want to use the same function several times and use a name for it, I have problems:
val plus1: (Int,Int,Int)->Int = {a,b,c->a+b+c} //this is OK
...
fun plus2(a:Int, b:Int, c:Int)=a+b+c // this too
...
println(apply3(1,2,3,plus1)) // this is allowed
...
println(apply3(1,2,3,plus2)) // this is NOT allowed
The last line is forbidden. With message:
Type mismatch
Required: (Int,Int,Int)->Int
Found: Int
Why? For me, plus2 and plus2 are the same things?
This post has an answer that advises to use ::plus2 in my case. This helps technically but does not explain the difference between these two functions.