Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A gentle introduction to functional programming

A gentle introduction to functional programming

Stefano Armenes

April 20, 2020
Tweet

More Decks by Stefano Armenes

Other Decks in Programming

Transcript

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

    APRIL 2020 Luca Di Stefano, Luca Ruzzola, Stefano Armenes
  2. A GENTLE INTRODUCTION TO FUNCTIONAL PROGRAMMING No side-effects, really? -

    any operation that interacts with an external system - out-of-scope resources mutations - exceptions
  3. A GENTLE INTRODUCTION TO FUNCTIONAL PROGRAMMING Referential transparency is all

    about expression Is this function referential transparent?
  4. 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.
  5. 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. Benefits - readability - parallelisation - memoization - more testable
  6. 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
  7. 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))
  8. 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?
  9. A GENTLE INTRODUCTION TO FUNCTIONAL PROGRAMMING Monads are your functional

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