id/email
password
forgot password | create account
about | help | prefs
ReadingBatcode reading practice

 

 

Lambda IntroIntLambda4

prev  |  next  |  chance

// Higher-order function as a return type
fun funcGena(i: Int): (Int) -> Int = { j: Int -> j * i }

// Higher-order function as a return type
fun funcGenb(i: Int): (Int) -> Int = { it * i }

fun funcWithInvoke(i: Int, j: Int): Int = funcGena(i).invoke(j)

fun funcNoInvoke(i: Int, j: Int): Int = funcGenb(i)(j)

Function Call  Return Value
funcWithInvoke(5, 6)
funcWithInvoke(10, 2)
funcNoInvoke(20, 5)
funcNoInvoke(30, 3)
funcNoInvoke(40, 4)

Experiment with this code on Gitpod.io or as a Kotlin Playground

⬅ Back