Extract Payload for enum cases having associated value

To provide a more real-world example, we covered a compelling reason for enum key paths/properties this week on Point-Free:

Though this video is behind a paywall, our code is always open source:

In particular we show how reducer architecture can be modularized and reconstituted using a couple succinct operations:

  1. An operation that converts Reducer<LocalState, LocalAction> to Reducer<GlobalState, GlobalAction>
  2. An operation that combines reducers that work on the same state and action type together

The first operation cannot succinctly transform LocalActions into GlobalActions in a performant manner without compiler help and enum properties and key paths perfectly handle this today (with a little boilerplate that ideally the compiler handles for us).

5 Likes