Stefano Armenes
April 20, 2020
310

# A gentle introduction to functional programming

April 20, 2020

## Transcript

1. ### A GENTLE INTRODUCTION TO FUNCTIONAL PROGRAMMING ENGINEERING MEETUP - 20TH

APRIL 2020 Luca Di Stefano, Luca Ruzzola, Stefano Armenes

3. ### A GENTLE INTRODUCTION TO FUNCTIONAL PROGRAMMING Pillars - referential transparency

- function composition - no side-eﬀects
4. ### A GENTLE INTRODUCTION TO FUNCTIONAL PROGRAMMING No side-eﬀects, really? -

any operation that interacts with an external system - out-of-scope resources mutations - exceptions
5. ### A GENTLE INTRODUCTION TO FUNCTIONAL PROGRAMMING ANYTHING IS A FUNCTION

…or better, an expression!
6. ### A GENTLE INTRODUCTION TO FUNCTIONAL PROGRAMMING Referential transparency is all

about expression Is this function referential transparent?

9. ### A GENTLE INTRODUCTION TO FUNCTIONAL PROGRAMMING Pure function A pure

function is a function that, given the same input, always returns the same output without producing any side-effect.
10. ### A GENTLE INTRODUCTION TO FUNCTIONAL PROGRAMMING Pure function A pure

function is a function that, given the same input, always returns the same output without producing any side-effect. Beneﬁts - readability - parallelisation - memoization - more testable
11. ### A GENTLE INTRODUCTION TO FUNCTIONAL PROGRAMMING We can compose two

functions f and g when f domain is a subset of g domain. f ∘ g === f(g(x)) Composing functions
12. ### A GENTLE INTRODUCTION TO FUNCTIONAL PROGRAMMING Composing functions …but, we

are missing somethings! We can compose two functions f and g when f domain is a subset of g domain. f ∘ g === f(g(x))
13. ### A GENTLE INTRODUCTION TO FUNCTIONAL PROGRAMMING Partial functions We want

to live a world where every function is a total function Is this function total?
14. ### A GENTLE INTRODUCTION TO FUNCTIONAL PROGRAMMING Cool but, why my

computation fails? Option[T]

16. ### A GENTLE INTRODUCTION TO FUNCTIONAL PROGRAMMING Monads are your functional

design patterns! Choose what you need IO List Option Either Set Future … Try