June 2018
Intermediate to advanced
316 pages
6h 34m
English
With functional programming, you can write code that allows you to concentrate on business logic instead of specific implementations. The following example is written in an imperative style:
val numbers = listOf(1, 2, 3, 4, 5, 6, 7)val odds = ArrayList<Int>()for (i in 0..numbers.lastIndex) { val item = numbers[i] if (item % 2 != 0) { odds.add(item) }}
If we rewrite this code in a declarative style, it will look as follows:
val numbers = listOf(1, 2, 3, 4, 5, 6, 7)val odds = numbers.filter { it % 2 != 0 }
This code describes what it does instead of how it does it, making it easier to concentrate on the main logic of the application.
Read now
Unlock full access