pointfreeco / swift-case-paths

🧰 Case paths extends the key path hierarchy to enum cases.
https://www.pointfree.co/collections/enums-and-structs/case-paths
MIT License
907 stars 105 forks source link

Add reflection API for projecting into any enum value #103

Closed stephencelis closed 1 year ago

stephencelis commented 1 year ago

This PR reworks some of the extraction logic for case paths and exposes a @_spi(Reflection) helper for projecting the associated value of any enum into an existential Any. We can eliminate a bunch of work we're currently doing by always projecting into the field type described by the runtime and then we can further attempt to cast to the extracted payload.

Fixes #83.

There are probably some performance improvements that can be made, but the benchmarks appear to perform as well as they do on main.

/cc @mayoff