Get the latest tech news
Parser Combinators Beat Regexes
Someone online was solving Advent of Code problems, and had a question about last years’ day 3. They had a working solution using regular expressions (regexes) on String values, but they wanted to use ByteString values instead for performance reasons.
This solution uses the attoparsec library, which is made to work with ByteString values specifically, since the person who asked the question seemed to care about performance. This is written in what one might call direct, monadic style, doing just what was requested in the first part of the Advent of Code puzzle, using do notation for sequencing. We could rewrite it to be neater, but we will resist refactoring for now; we never know what twist in the requirements will be introduced in the second part of an Advent of Code puzzle.
Or read this on Hacker News