Getting (More) Work Done with Extensible Effects in Scala
YOW! Lambda Jam 2018
This hands-on, code-centric session teaches attendees how effectful functional programming can be used to tackle the often messy, IO-heavy problems found in industry. We will use the Scala Eff monad library to incrementally build and extend a directory scanner.
Participants without any previous background in Eff or effectful FP have a smooth on-ramp. A series of refactoring exercises incrementally transforms an imperative program into a purely functional, effectful programming, introducing the Eff API along the way:
- The Async effect to model asynchronous requests
- Using Either effects for error handling
- Using Reader effects for dependency injection
- Writer effects for logging
For those with previous Eff experience, or have done my Eff workshop at Lambdajam 2017, there are new exercises that dig deeper into Eff:
- Programming stateful systems with the State effect
- Combining effects and functional optics
- Two different approaches to side-effects: catch-all IO vs focussed effect DSLs
The Eff library is an implementation of Extensible Effects in Scala, developed by Eric Torreborre. It is inspired by Oleg Kiselyov’s Haskell paper ‘Freer Monads, More Extensible Effects’ . Like Monad Transformer stacks and the Free monad, it provides an organising principle for the construction of pure functional programs.
Materials are available at benhutchison Getting Work Done With Extensible Effect. Solutions are included for all exercises.