Lesson 5: Refactoring with Either

Contents
  • Introducing Either
  • The Either Monad
  • Using Either
Video
  • 10 minutes

We’ve come a long way already in our code, but some things have been dissatisfying. For one thing, we have no way to distinguish between different errors (they are all Nothing) or which error is short-circuiting our program. Using Either, a sum type similar to Maybe, allows us to pass around more information about our error cases. This lesson refactors the previous lesson’s code to use Either and its Monad instead of Maybe.

Sign up for access to the full page, plus the complete archive and all the latest content.