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
904 stars 105 forks source link

Add Optional case path for chaining into `some` case #139

Closed stephencelis closed 8 months ago

stephencelis commented 8 months ago

Swift allows us to omit .some and does the work to implicitly wrap optionals for us:

let _: Int? = 42

// Equivalent to:
let _: Int? = .some(42)

So why not do the same in case paths? Instead of forcing .some when going through an optional, we can go directly:

enum Foo { case bar(Bar?) }
enum Bar { case baz(Int) }

// Before:
\Foo.Cases.bar.some.baz

// After:
\Foo.Cases.bar.baz