CasePaths for enums containing non-enum state #170
Unanswered
technicated
asked this question in
Q&A
Replies: 2 comments 1 reply
-
|
A case path describes extracting and embedding an associated value from/in an enum: @CasePathable enum Foo { case bar(Int) }
let barPath: CaseKeyPath<Foo, Int> = \.bar
let bar = barPath(42) // Foo.bar(42)
bar[case: barPath] // Optional.some(42)When you chain into a property of a product type (like the tuple of values in @CasePathable enum Foo { case bar(int: Int, string: String) }
let barPath: CaseKeyPath<Foo, String> = \.bar.string
let bar = barPath("Blob") // Foo.bar(int: ⁉️, string: "Blob")There's no way to embed a string in such a theoretical case path because This has come up before, so for reference: #127 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone 👋
I have a question about CasePaths with non-enum nested objects, but first, a little bit of context.
I have developed a TypeScript library that tries to mimic Swift enums, and in this library I am also modeling CasePaths based on what I've learned from Point-Free videos. This library works surprisingly well given what TypeScript has to offer!
Now, for a TypeScript project at work, I am creating API routes that resemble those in Isoword, but the routes are more elaborate and nested since they are REST APIs.
Here are some example routes:
What we have written in TS using my library could be translated in Swift like:
However, I am encountering issues with CasePaths for
PropertiesandVisureroutes. Autocompletion only shows results for some cases, and for\.certifications.(properties | visure)it only shows.never.What am I missing? Am I doing something wrong? Is there a better way to do this? Since my ts-enums library works the same as swift-case-paths, I am encountering the same problem in my codebase.
Thank you everyone for your support!
Beta Was this translation helpful? Give feedback.
All reactions