Learning Kotlin: Lambdas

Submitted by Robert MacLean on Tue, 06/19/2018 - 09:00
**More Information** * [The code being referenced](https://github.com/Kotlin/kotlin-koans/blob/master/src/i_introduction/_4_Lambdas/n04Lambdas.kt). * This is the 5th post in a multipart series. If you want to read more, see our [series index](/learning-kotlin-introduction) So following C#, Kotlin has Lambda support with the change if `=>` becoming `->` and the Koan starts with some nice examples at the start: fun example() {       val sum = { x: Int, y: Int -> x + y }     val square: (Int) -> Int = { x -> x * x }       sum(1, square(2)) == 5 } Basically, though, the code that needs to be done is to check a collection if all items are even, which is easily done with: fun task4(collection: Collection<Int>): Boolean = collection.any({item -> item % 2 == 0})