Unlock This Episode
Our Free plan includes 1 subscriber-only episode of your choice, plus weekly updates from our newsletter.
It has been over a year since we last talked about parsers on Point-Free, and it was more than one year before that since we first introduced the idea of parsers. There’s still so much we want to discuss when it comes to parsing, and so we are reviving the topic this week to explore some really exciting advancements we’ve made recently.
The last time we talked about parsing we heavily focused on:
- Generalization, which allows parsers to process any type of input into any type of output;
- Ergonomics, which allows us to construct parsers in the most fluent way possible; and
- Performance, which allows our parsers to be as performant as ad-hoc, hand-rolled parsers, and sometimes even more performant.
Starting this week we are going to continue a bit more with the ergonomics angle of parsing by seeing what Swift’s result builders have to offer parsing. Result builders are a relatively new feature of Swift that were primarily created in order to facilitate a concise syntax for SwiftUI views, but there are many applications for builders.
Parsing is a surprisingly ubiquitous problem in programming. Every time we construct an integer or a URL from a string, we are technically doing parsing. After demonstrating the many types of parsing that Apple gives us access to, we will take a step back and define the essence of parsing in a single type. That type supports many wonderful types of compositions, and allows us to break large, complex parsing problems into small, understandable units.
A library for turning nebulous data into well-structured data, with a focus on composition, performance, and generality.
The Swift core team’s proposal and experimental repository for declarative string processing, which includes result builder syntax for creating regular expressions, and inspired us to explore result builders for parsing.
Why does the
mapfunction appear in every programming language supporting “functional” concepts? And why does Swift have two
mapfunctions? We will answer these questions and show that
maphas many universal properties, and is in some sense unique.