Justin Heyes-Jones – What’s Ap?

Justin Heyes-Jones

Justin Heyes-Jones

Justin is a Scala developer at the consulting company Yoppworks. He works from his home in Vancouver, Canada. He has been programming in Scala for eight years and is very interested (semi-fanatical) in pure functional programming.

Apart from writing code to solve business problems, his other great joy is bringing seemingly complex technical topics to a wider audience. Although my mum tells me she lives near one of the One Direction guys, I don’t know his name sorry.

What's Ap?

Applicative is a lesser know type class that lies between Functor and Monad in terms of power. In this talk, which presumes no previous experience of pure functional programming, I will talk about how flatMap and map are familiar to most Scala programmers and how they relate to Functors and Monads from category theory. Next, I will show where the Applicative type class fits into the picture, particularly how it can be used in your programs to do things that are not possible with Functor or Monad.

Looking at the ap function in detail I’ll show how it is applied to different effect types from List and Option to Reader and IO, and show the motivation for its existence in the Cats library. Next, I’ll show how Applicative lets us work on multiple effects and pass them to pure functions, how to run independent effects concurrently to do things like compose images and make calls to external services.

Finally, a look at how to efficiently implement an Applicative instance to avoid redundant work, by taking advantage of the fact that we can implement Applicative using different primitives depending on the effect type.

SoftwareMilling around OSS