So, we’ve done some pretty interesting things just now. We decided to house all of the case paths for an enum inside an inner Cases
type, that way we don’t pollute the enum with a bunch of superfluous properties that will clutter autocomplete and the documentation of your types. And then we flipped the notion of “case path” on its head by instead thinking of it as a key path that locates a case path inside that Cases
type. That instantly gave us key path syntax to procure case paths, and gave us type inference and nice autocomplete for free!
But of course what we have done so far is not how anyone would want to write their applications. No one is going to define the Cases
type for each one of their enums and then fill those types with properties for each case in the enum. That is a long, laborious process that is very easy to get wrong.
And this is a perfect use case for a macro. We should be able to annotate our enums with some kind of @CasePathable
macro, and have all of that code generated for us automatically. This will be the first truly useful macro that we have built on Point-Free, and it is not a trivial one. There are some tricky aspects to it, and luckily we have our new MacroTesting library to help us each step of the way.
So, let’s see what it takes to write a macro to generate all of this case path boilerplate automatically.