Some basic FP concepts 
@friemens
Why is mutable state problematic? 
Functions as Values 
Programming without assignment? 
Handle mutable state safely 
Leave data alone!
Nothing new here! 
1930s Lambda Calculus 
1960s Lisp 
1990s Haskell
„Familiarity and Simplicity are orthogonal concepts.“ 
Rich Hickey
Why is mutable state problematic?
A system without side-effects is useless, 
but...
Mutation hinders reasoning.
Mutable state increases test effort.
1. 2. 
Mutation introduces order.
Mutable state makes concurrency hard.
FP programming 
OOP programming 
Side-effects restrict how the machine can help us.
Context dependance 
Pure Functions 
Side-effects 
The future-proof structure of any software system.
Functions as Values
Pure Function 
= 
No side-effects 
+ 
Result depends only on param values
Lambda Expression 
= 
An anonymous function.
Closure 
= 
A function + some captured environment.
Higher-Order Function 
Fn: [Any... -> Any] 
F: [Any -> Fn] 
G: [Fn -> Any] 
H: [Fn -> Fn] 
A function that 
- does something with another function 
- or returns a function, 
- or both.
Function Application 
Fn: [Any... -> Any] 
apply: [Fn Any* -> Any] 
Take collection of param values 
and invoke function.
Partial Application 
Fn: [Any1...Anym...Anyn -> Any] 
partial: [Fn Any1...Anym -> 
[Anym+1...Anyn -> Any]] 
Create a new function with some arguments 
fixed. 
(„Currying“ is automatic partial application.)
Function Composition 
F: [X -> Y] 
G: [Y -> Z] 
compose: [G F -> [X -> Z]] 
Concatenate computations.
Programming without assignment?
Good bye =, for, while and cousins, ... 
… say hello to let, map, filter and friends!
map 
Thinking in collection transformations. 
xs 
ys 
z 
filter 
concat reduce
map filter mapcat into 
Don't be so eager!
Cheap parallelization. 
reduce 
combine
Handle mutable state safely
State x State x' 
f 
swap! 
Identity 
Separate state from identity.
Give identities well-defined concurrency semantics.
Share immutable state liberally. 
Be restrictive with access to identities.
Leave data alone!
BigHero 
-a string 
-a map 
+method1 
+method2 
+method3 
Objects claim feature completeness.
You can't foresee the future.
You will violate the Open-Closed-Principle.
„Inventing a class with its own interface 
to hold a piece of information is like inventing 
a new language to write every short story. “ 
Rich Hickey
Data is simple.
DSL 
API 
Data Model
Wrap up
OO makes code understandable 
by encapsulating moving parts. 
FP makes code understandable 
by minimizing moving parts. 
Michael Feathers
The future is functional. 
You need to practice FP before you „get“ it. 
It's more fun!
Questions?

Some basic FP concepts