I didn't say they were the same, but they are two sides of the same coin: one is the dual of the other, which is great! It gives us the opportunity to take every feature on structs and explore its dual on enums (and vice versa). There are a lot of fascinating examples!
It is true that enums are great for enumerating actions and events, but remember that Optional
and Result
are enums, and it's common to reassign mutable optional variables (which is data manipulation), or using map
and flatMap
to transform the associated value.
Even more app-specific enums, like those actions and events, have reason to be manipulated. If you have an AppAction
enum that enumerates over smaller sets of actions for smaller screens, like case login(LoginAction)
and case signUp(SignUpAction)
, etc., you could write isolated business logic for login actions, and isolated business logic for signup actions, but you could not compose that logic together generically to combine them into your application logic without enum key paths (or a lot of manual boilerplate).
I have to disagree. I think this is very much on-topic and deserves discussion given the dual nature of enums and structs. To ignore data manipulation in any design for data access would be a hugely missed opportunity.