URL parser in functional style. Part 2.

In previous part we started to write base components of URL parser. Time to extend it and add some additional functionality, like conditional, optional and wildcard patterns. Conditional pattern This pattern should parse either one pattern or another. This kind of parameter type can be expressed with Either<A, B> type defined as a simple generic enum with two cases. enum Either<A, B> { case left(A), right(B) } Using this type we can compose parser and printer. Parser will try to parse left pattern first and return matched value wrapped in Either.left, otherwise it »

URL parser in functional style. Part 1.

When I published one of my previous posts about deeplinks and then decided to turn it into a framework it turned out that Brandon Williams was working on a similar thing for his Point-Free project, but related to parsing http requests for web framework. As parsing URLs is a subset of this problem I decided to go through his implementation and apply the same technique to rewrite parser that I have written in imperative way (and probably not in the best way) in a functional style. Just to see where it goes and as exercise in a functional programming. So »