So creating a case path is quite easy, but there are a lot of things not completely right with this code snippet. First, it is not right to pollute the Result
namespace with these static vars, it would be better to have a different place to store them. Also, there is some boilerplate involved in creating these case paths. We see it here with this if case let
stuff when implementing the extract
, and basically every case path we create will look exactly like this, and after awhile it’s going to be a pain to have to write over and over.
We are going to solve both of those problems soon, but first we want to explore some of the properties of case paths and show the similarities with key paths. There are some operations that the Swift standard library provides for key paths, and we of course would expect that there is some version of those operations for case paths too.