Skip to content

Instantly share code, notes, and snippets.

@leontabak
Created September 24, 2021 18:08
Show Gist options
  • Save leontabak/bc9be64f0fed8ee09068a47efe923b66 to your computer and use it in GitHub Desktop.
Save leontabak/bc9be64f0fed8ee09068a47efe923b66 to your computer and use it in GitHub Desktop.
introducing lambda in Kotlin
fun main() {
println("Experiment with lambda functions.")
val doublePlusOne: (Int) -> Int = {x:Int-> 2 * x + 1}
println( doublePlusOne(3) )
val data = (0..3).map( doublePlusOne )
println( data::class.simpleName )
println( data )
val odd: (Int) -> Boolean = {it % 2 == 1}
val samples = (0 until 16).filter(odd)
println( samples )
val measurements = List<Int>(12){ it * it }
println( measurements )
val observations = List<Int>(12){it}
print( observations )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment