Folding and Reducing List
fold() combines all elements of a list, in order to generate a single result. Here is how we can use fold() to calculate the sum -
87 posts · page 7 of 11
fold() combines all elements of a list, in order to generate a single result. Here is how we can use fold() to calculate the sum -
What is Sequence? A Kotlin Sequence is like a List, but you can only iterate. You cannot index into Sequence. And this restriction produces very efficient chained operations.
Maps are extremely useful programming tools, and there are numerous ways to construct them. Let’s recap what we learned in List.
We love List. In fact, many of our work involve using List to store many piece of information. We then apply different operations on List to make it what we need for our application.
What is it? If you are coming from JavaScript, this concept may sound familiar to you. Otherwise, here is what it means.
A truly functional programming language like Javascript allows us to assign the function as a variable. Take an example of this:
Most functional programming has a great support for working with collections and so is Kotlin. If you are coding with Kotlin for sometimes, you might notice about map(), filter(), any() and forEach().
To some people, lambda may seem like syntax sugar, but it is more than that. If you have to repeat some codes with minor modification, you can leverage on the power of lambda.