Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-5822] Enum key paths #48392

Open
stephencelis opened this issue Sep 1, 2017 · 3 comments
Open

[SR-5822] Enum key paths #48392

stephencelis opened this issue Sep 1, 2017 · 3 comments
Labels
compiler The Swift compiler in itself feature A feature request or implementation improvement

Comments

@stephencelis
Copy link
Contributor

Previous ID SR-5822
Radar None
Original Reporter @stephencelis
Type Improvement
Additional Detail from JIRA
Votes 4
Component/s Compiler
Labels Improvement, LanguageFeatureRequest
Assignee None
Priority Medium

md5: 451b3f7df8e7d6b288d80f2e95904a96

Issue Description:

Key paths currently only work for product types, but sum types would benefit, as well!

enum Result<T> {
  case success(T)
  case failure(Error)
}

\Result<String>.success?.count
// KeyPath<Result<String>, Int?>

let kp = \Result<User>.success?.name
let result = Result.success(User(name: "an anonymous imp"))
result[keyPath: kp] = "Rumpelstiltskin"

if case let .success(user) = result {
  print(user.name)
}
// prints "Rumpelstiltskin"
@belkadan
Copy link
Contributor

belkadan commented Sep 5, 2017

cc @jckarter

@CodaFi
Copy link
Member

CodaFi commented Sep 8, 2017

All of these keypaths would have to be optionally-typed because we don't have a guaranteed projection (prism-like) like we do for product types (lens-like).

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@fwgreen
Copy link

fwgreen commented May 24, 2022

For anyone still watching this. #58940

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler in itself feature A feature request or implementation improvement
Projects
None yet
Development

No branches or pull requests

4 participants