Improving `taggedEnum` with Proxy for a Better API
I had an idea to make
taggedEnum
taggedEnum
better. If we use
Proxy
Proxy
we can get this api:
type State = Data.TaggedEnum<{ Foo: {...} Bar: {}}>const State = Data.taggedEnum<State>()State.Foo({...}) // <- Proxy catches the access to the `Foo` key, placing it as the keyState.Bar()
type State = Data.TaggedEnum<{ Foo: {...} Bar: {}}>const State = Data.taggedEnum<State>()State.Foo({...}) // <- Proxy catches the access to the `Foo` key, placing it as the keyState.Bar()
@gcanti@Tim Smart What do you think? It's a better feeling api at the cost of a slight perf hit. This can be overloaded on the regular function object so that it's an opt-in api. I find myself using