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

Elvis operator (AKA Optional chaining) #768

Open
emil14 opened this issue Nov 17, 2024 · 0 comments
Open

Elvis operator (AKA Optional chaining) #768

emil14 opened this issue Nov 17, 2024 · 0 comments
Assignees
Labels

Comments

@emil14
Copy link
Collaborator

emil14 commented Nov 17, 2024

In TS and Kotlin we can use ?. to access nullable fields on objects safely, and we can infinitely chain them

foo?.bar?.baz?.bax

We already have "error-guard" operator ? for ergonomic error handling, and there're some ideas for #746 where expressions like d[k] or l[i] return maybe (or Option, if we will go full rust-like in #751), also we have struct selectors syntax foo -> .bar -> .baz but what we don't have is ergonomic syntax for safe access to struct fields that are maybe/option if there's some nesting

type Foo struct {
  bar maybe<struct {
    baz maybe<struct{
      bax maybe<int>
    }>
  }>
}

...

foo -> ?.bar?.baz?.bax -> match {
  some -> println
  none -> panic
}
@emil14 emil14 added the Idea label Nov 17, 2024
@emil14 emil14 self-assigned this Nov 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant