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

Composing CaseKeyPaths and KeyPaths #126

Closed davdroman closed 10 months ago

davdroman commented 10 months ago

Thanks to the new macro implementation, CaseKeyPaths are naturally composable via dot syntax just as KeyPaths, but when trying to compose CaseKeyPaths with normal KeyPaths unfortunately the compiler errors out.

@CasePathable
enum PaymentType {
    case creditCard(CreditCard)
}

struct CreditCard {
    var number: String
    // ...
}

\PaymentType.Cases.creditCard.number // 🛑 Generic parameter 'AppendedValue' could not be inferred
                                     // 🛑 Subscript 'subscript(dynamicMember:)' requires that 'CreditCard' conform to 'CasePathable'

Is this a technical limitation that can't be circumvented, or something pending to be implemented in the future perhaps?

stephencelis commented 10 months ago

@davdroman Just curious, what is your expectation with the above path and how would you like it to be used?

I don't think this is technically a bug with the library, though, just a conversation about its current feature set, so I'm going convert this to a discussion.