Lesson 8: Refactoring with Validation

Contents
  • Introducing validation
  • Adding a dependency
  • Nominal refactoring
  • An Error semigroup
  • Using Applicative
  • Conclusion
Video
  • 25 minutes

We do a thorough refactoring 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.

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