January 2019
Intermediate to advanced
392 pages
10h 11m
English
We used to use the imperative style of programming when writing object-oriented programming, but for functional programming, a more natural style is declarative. The declarative style assumes that our code describes what to do, instead of how to do it, as is usual with imperative programming.
The following example demonstrates how functional programming can be useful in certain cases. Let's imagine that we have a list of numbers, and we want to find the number that is greater than 4. In the imperative style, this may look as follows:
fun imperative() {val numbers = listOf(1, 4, 6, 2, 9)for (i in 0 until numbers.lastIndex) {if (numbers[i] > 4) {println(numbers) } }}
As you can see, we have to use a lot of ...
Read now
Unlock full access