It’s a Way of Thinking

So to a first approximation, functional programming is about programming with pure functions and immutable state, unlike imperative programming, which relies heavily on mutability. Around this immutable core there is a set of language techniques and features that replace mutable imperative techniques. Examining these will give us a deeper feeling for what it is to think and program functionally.

Let’s take a look at a simple example: filtering a list so it only contains odd numbers.

 public​ List<Integer> filterOdds(List<Integer> list) {
  List<Integer> filteredList = ​new​ ArrayList<Integer>();
 for​(Integer current : list) {
 if​(1 == current % 2) {
 return​ filteredList; ...

Get Functional Programming: A PragPub Anthology now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.