Skip to main content

Posts

Showing posts from 2020

Understanding lambda in Kotlin

Kotlin is very concise language. You can achieve same functionality with fewer characters compared to Java. But as an experienced developer, it was easy for me to switch from Java to Kotlin. Same might not be true for those who are new to programming. I had tough time explaining how Lambda works to a trainee who was new to programming. For instance, I was trying to explain a simple map function that maps objects of one type to another. I have two simple classes and a simple usage of map function I came up with following step by step code to explain what's actually going on. All the code snippets do the exact same thing. Converting imperative to functional code at the end. Extract the list of journals to new variable. The map function is being executed here, we can specify the round brackets to be explicit The code after map function including the curly braces is actually a lambda. I