Created
September 24, 2021 18:08
-
-
Save leontabak/bc9be64f0fed8ee09068a47efe923b66 to your computer and use it in GitHub Desktop.
introducing lambda in Kotlin
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 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