What even is a cat? (WIP)

Agenda

  • Motivation
  • Recap: FP without effects
  • Examples of effects
  • How to compose effects

Motivation

I saw something like "F[_]: Applicative" in the code.

Do we use this anywhere else already?

Short answer: Yes, in many places

Longer answer: ...this talk

Recap: FP

"Functional Programming is writing programs with (pure) functions and (immutable) data"

~ Me ;)

Functions

Data

+

Focus of this talk

Recap: FP

If a function...

  • ...is defined for every possible input, it is called total
     
  • ...only uses its input to calculate its output and does nothing else, it is called pure (= no side-effects)

=> The ideal is to make all functions total and pure

Recap: Function composition

In reality...

 

  • Partiality (Option)
     

  • Errors (Either)
     

  • Nondeterminism (List)
     

  • Concurrency (Future)
     
  • ...and many more

 

A => Option[B]
 

A => Either[?, B]


A => List[B]
 

A => Future[B]

The Foundation

Functor

Applicative

Monad

map

ap

pure

flatMap

pure

(flatten)

(product, zip, mapN)

"Transform values inside an effect"

"Compose effects independently"

"Compose effects dependently"

Let's try an example

Inspirations for this talk

What even is a cat? (WIP)

By Felix Bruckmeier

What even is a cat? (WIP)

FP with effects in Scala (using cats)

  • 103