Mucking around with this in a Playground.
Update: Turns out doing this in a Playground wasn't a great idea - the overhead makes it really slow, sometimes to the point of beachballing Xcode. Much better to do this in a standalone executable. Since I started down this path, I'm going to keep updating the playground, but I don't recommend running it in this environment.
Building and running in Xcode 12.3.