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

 

 

Lambda IntroNoArgLambda3

prev  |  next  |  chance

val constVal1: () -> Int = { 4 }

val constVal2: () -> Int = { 6 }

fun constFunc(): Int = 8

val constVal3: () -> Int = ::constFunc

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

Function Call  Return Value
funcNoArg3(5, constVal1)
funcNoArg3(10, constVal2)
funcNoArg3(6, ::constFunc)
funcNoArg3(20, constVal3)

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

⬅ Back