Skip to content

Instantly share code, notes, and snippets.

@shahsurajk
Last active November 27, 2019 19:05
Show Gist options
  • Save shahsurajk/3a854eaa4d395c6808a9ce4d2b456dab to your computer and use it in GitHub Desktop.
Save shahsurajk/3a854eaa4d395c6808a9ce4d2b456dab to your computer and use it in GitHub Desktop.
Non-inlined lambda with closure
fun testLambdas(index: Int, myLambda: (index: Int) -> Unit){
myLambda.invoke(index+1)
}
fun IntArray.myBigLoopWithClosure(salt: Double){
forEach {
testLambdas(it) { myLambda ->
// the salt value over here is captured in a closure.
// thus, this will create a new instance of the lambda for every iteration
println(myLambda * salt)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment