September 2015
Intermediate to advanced
250 pages
6h 40m
English
At the core of functional programming are functions or so-called higher-order functions. To get a feel for what these are, let’s start with a familiar function.
To find the sum of values in a given range 1 to number we’d probably write code like this:
| | def sum(number: Int) = { |
| | var result = 0 |
| | for(i <- 1 to number) { |
| | result += i |
| | } |
| | result |
| | } |
That’s familiar code—we’ve all written code like this a million times over in different languages. That’s called imperative style—you tell not only what to do, but also how to do it. That’s dictating a low level of details. In Scala, you can write imperative code like this where it make sense, but you’re not restricted to that.
While this code got the work done, ...
Read now
Unlock full access