Lesson 8: Refactoring with Validation

Video
  • 24 minutes
Tags
Validation Applicative Semigroup

We do a thorough refactoring of the code to switch from Either to Validation. Despite the fact that those two types are isomorphic to each otherBy “isomorphic to each other” we mean that you could losslessly convert Either to Validation and vice versa.

, their Applicative instances are quite different and switching to Validation allows us to accumulate errors on the left. Since that Applicative relies on having an instance of Semigroup to handle the accumulationA semigroup operation is a binary associative operation; in the case of the String types we’re dealing with, the operation is list concatenation (but without an empty string as an identity value).

, we need to write a Semigroup instance for our Error newtype.

This lesson will be released after Julie recovers from bronchitis.