Ever since key paths were introduced, giving us a tool to abstract over members of structs and enums, I have felt that there should be an equivalent tool for enums – particularly enums with associated values. I’ve been assuming this would take a similar form to key paths, but another approach recently occurred to me.
Let’s start with a motivating example: event handling. If you used Swift for Mac or Windows application development in the 90s, your code would have contained something like this:
// AppController.swift
func handleEvent(_ event: Event) {