2. The functional programming jargon is “scary”!
● Function arity
● Pure functions
● Referential transparency
● Side effects
● Partial application
● Currying
● Function Composition
● Lazy evaluation
3. Fear not my friends!
● Encapsulation
● Class
● Property
● Method
● Object
● Inheritance
● Polymorphism
Do you remember how you felt the first time you encountered the Object-oriented jargon?
4. Pure Functions
Purity (AKA referential transparency) means “every time you pass the same inputs, you
always get the same outputs”.
A pure function is free of side effects. A side effect refers simply to
the modification of some kind of state.
Any operation which modifies the state of the computer or which
interacts with the outside world is said to have a side effect.
5. Immutability
An immutable object is an object whose state cannot be modified after it is created. In JavaScript
objects are not immutable and our pure functions should avoid mutating its arguments (side
effect). We can achieve this by using a library like immutable.js and avoiding the JavaScript
mutator methods!
6. Function Partial Application
Partial application is the process of fixing a number of arguments to a function, producing
another function of smaller arity.
Arity refers to the number of arguments a function can accept. This
might be none, one (unary), two (binary) or more (polyadic). You
can also have functions that take a variable number of arguments,
(variadic functions).
7. Currying
Currying is the process of taking a function that accepts N arguments and turning it into a
chained series of N functions each taking 1 argument.
8. Function Composition
The act or mechanism of combining simple functions to build more complicated ones.
Unary functions are easier to compose. Currying helps us to perform function composition.
Functional programming manages complexity via composition as opposed to data encapsulation.
9. How to learn more?
Books:
● Functional Programming in JavaScript by Dan Mantyla
● Functional Programming in JavaScript by Luis Atencio
● Reactive Programming with RxJS by Sergi Mansilla
Libraries:
● React & Redux
● Ramda
● RxJS
● Immutable
● Cycle
The goals of this talk:
If you already know FP you will find it too basic :(
If it is the first time that you hear about FP I would like you to feel curious about it by the end of this talk.
If you think that FP is too hard I would like you to feel less scared by it by the end of this talk.
It is hard because there are a lot of new terms and it is a different way of thinking.
OOP once also was a different way of thinking and had a lot of terms and today you know it well :)