Last active
November 27, 2019 19:05
-
-
Save shahsurajk/3a854eaa4d395c6808a9ce4d2b456dab to your computer and use it in GitHub Desktop.
Non-inlined lambda with closure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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