Functional Programming
& Immutable Data
Functional programming
Functional programming is a programming paradigm
that treats computation as the evaluation of
mathematical functions and avoids changing-state
and mutable data.
Functional programming
Is the programming using mathematical functions
Mathematical functions
The representations of expressions that when called
will return ever the same result.
I = V/R
current(voltage,resistance) = voltage/resistance;
current(1,1000) = 1/1000;

is equal 0.001
current(1,1000) = 1/1000;

is equal 0.001
current(1,1000) = 1/1000;

is equal 0.001
current(1,1000) = 1/1000;

is equal 0.001
current(1,1000) = 1/1000;

is equal 0.001
current(1,1000) = 1/1000;

is equal 0.001
current(1,1000) = 1/1000;

is equal 0.001
current(1,1000) = 1/1000;

is equal 0.001
current(1,1000) = 1/1000;

is equal 0.001
current(1,1000) = 1/1000;

is equal 0.001
No matter how many times you apply!
Ever result will be equal!
Contrast
Imperative
This is about "how"!
Functional
This is about “what”!
High-order functions
Lazy valuation
High-order functions
Is a function that takes one or more functions as arguments and
can returns a function as its result.
Lisp, Erlang, Haskell, Javascript, Java8, Scala…
List, HashMap, Map, Reduce, Filter, Reject, ForEach
List, HashMap
Reduce
Iterate over the list and reduce the list values in one value.
Map
Iterate over a list and create other list with results of operations applied each item of list.
High-order functions
Is a function that takes one or more functions as arguments and
can returns a function as its result.
Then! Functional programming is a style of
programming that compose functions to produce
one result.
This is a new mindset.
Because in this scene, the minor part of your architecture
is not more a "Classe", now is a "Function".
Now you need creating pieces for transform inputted
data with focus on the desired result.
Example
I have a list of people and I need all people
who have more than 18 years old.
Count how many times a letter repeats but only on the people
who have more than 18 years old.
When your code is divided in very small
pieces is easy for you code using single
responsibility.
You reuse more and write less.
Debugging is simple
The TDD and BDD is pretty simple
You win a powerful approach for
improve performance
Memoization
In computing, memoization is an optimization
technique used primarily to speed up computer
programs by storing the results of expensive function
calls and returning the cached result
numbers.map(sum)
P1
P2
P3
P4
Cluster
Big Data
Realtime applications
Immutable data
The value is not changed in life cycle, like constants.
The data is created to receive changes, like variables.
Mutable data
The biggest problems with mutable data is that you need worry
with scopes, concurrency and parallelism.
Mutable data
Immutable data is only a good idea!
But in functional programing its is the main ideia.
You couldn't change the asks,
only create answers.
This is more fluid, because the
flows is very predictable.
My motivation for this talk is about
REDUX
Only one entry point immutable. Single state.
Apply reducers for produce new state.
Simplify tests, write less and improve productivity.
SimplesDental
Luiz H. Estácio
luizstacio
luiz@simplesdental.com
😎
Thanks 😁

Functional programming & immutable data.