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

 

 

Lambda IntroIntLambda3

prev  |  next  |  chance

val tripleIt3: (Int) -> Int = { i: Int -> i * 3 }

// Simplify things with it
val quadItIt3: (Int) -> Int = { it * 4 }

fun doubleIt3(i: Int): Int = i * 2

val doubleIt3: (Int) -> Int = ::doubleIt3

// Higher-order function as a parameter
fun func3(i: Int, func: (Int) -> Int): Int = func.invoke(i)

Function Call  Return Value
func3(5, tripleIt3)
func3(10, quadItIt3)
func3(20, tripleIt3)
func3(30, ::doubleIt3)
func3(40, doubleIt3)

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

⬅ Back