KT
kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//#1
fun applyOp(x: Int, y: Int, op: (Int, Int) -> Int): Int = op(x, y)
/*
Function references: any function can be a lambda
So the same way lambdas can be passed as an
argument or saved to a variable, we can do
the same with regular functions.
*/
//#2
fun sumFun(x: Int, y: Int) = x + y
/*
This is doing the same, but instead of having
a variable that keeps the function, we just
have a function.
*/
fun main(args: Array<String>) {
println(
"*** Function references ***\n")
/*
Kotlin supports functions as a type,
what means that you can save a function
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run