Skip to content

Composing CaseKeyPaths and KeyPaths #127

Answered by stephencelis
davdroman asked this question in Q&A
Discussion options

You must be logged in to vote

@davdroman Both of the examples above are maybe too concrete to get at the meat of the issue, so I'd be curious if you have a sketch of how you were trying to use Scope.

One thing to note is that for access, if you use @dynamicMemberLookup you can get a key path to the underlying thing:

 let paymentType = PaymentType.creditCard(CreditCard(number: "12345"))
-paymentType[case: \.creditCard.number]      // 🛑
+paymentType[keyPath: \.creditCard?.number]  // Optional<String>("12345")

For setting into the thing it's more complicated. Remember that case paths can unconditionally embed. So say that theoretically \PaymentType.Cases.creditCard.number returned a CaseKeyPath<PaymentType, String>. The …

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
5 replies
@davdroman
Comment options

@davdroman
Comment options

@stephencelis
Comment options

Answer selected by davdroman
@davdroman
Comment options

@stephencelis
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #126 on November 14, 2023 00:34.