July 2023
Intermediate to advanced
670 pages
17h 13m
English
Before we close out this chapter, let’s address one more ergonomic inconvenience that has cropped up a few times: dealing with parsers that might fail. When we were manually building the parsing functions inside of FilePackParser this wasn’t such a big deal, but as we’ve been able to build more and more of our code out of smaller parsers that we are composing, having to manually construct a parser with a Left value starts to get inconvenient. Worse, it ties us to a specific representation of our errors. In the future, if we wanted to refactor our parser to not use Either, we’d need to change every single error in our code base.
One option here would be to factor out the error handing into its own function:
| | parseError ... |