RosettaCodeData/Task/Closures-Value-capture/Kotlin/closures-value-capture.kotlin
2017-09-25 22:28:19 +02:00

8 lines
265 B
Text

// version 1.0.6
fun main(args: Array<String>) {
// create an array of 10 anonymous functions which return the square of their index
val funcs = Array(10){ fun(): Int = it * it }
// call all but the last
(0 .. 8).forEach { println(funcs[it]()) }
}