Cats Type Classes
Functor, Monad, etc.
What Are Type Classes?
A type class is a pattern for ad-hoc polymorphism. It lets you add behavior to a type without modifying it. Cats is a Scala library that provides a rich hierarchy of type classes for functional programming.
Functor— things you canmapoverApplicative— combine independent effectsMonad— sequence dependent effects
Functor: map
A Functor[F] provides map. It transforms the value inside a context without changing the context's structure.
import cats.Functor
import cats.instances.option._
val f = Functor[Option].map(Some(2))(_ + 1)
println(f) // Some(3)All lessons in this course
- Cats Type Classes
- The IO Monad
- Composing IO
- Error Handling in IO