July 2017
Intermediate to advanced
284 pages
6h 45m
English
At its core, functional programming is about programming with pure, side-effect-free functions.
This is a pure function:
| | f(x) = <raise power="2">x</raise> |
So is this:
| | public int incrementCounter(int counter) { |
| | return counter++; |
| | } |
This is not:
| | private int counter = 0; |
| | public void incrementMutableCounter() { |
| | counter++; |
| | } |
The first two examples increment a counter by returning a new integer that’s one higher than the passed-in integer. The third example does the same thing but does it by mutating a bit of state that may be shared across many pieces of a program.
A definition: a function like incrementCounter that doesn’t rely on mutating state is called a pure function. And this purity ...
Read now
Unlock full access