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

Enhance ?: operator to support null dereference on lhs #69

Closed
jaccomoc opened this issue Nov 24, 2024 · 0 comments
Closed

Enhance ?: operator to support null dereference on lhs #69

jaccomoc opened this issue Nov 24, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@jaccomoc
Copy link
Owner

The ?: operator will return the right-hand-side value if the left-hand-side is null.
So we can write:

x.a.b.c ?: 'xxx'

This will return 'xxx' if x.a.b.c is null.
But if x.a.b or x.a or even x were null then we would get an error. If we want to cater for these possibly being null we have to write:

x?.a?.b?.c ?: 'xxx'

It would be nice if the ?: would return the right-hand-side value if either the left-hand-side evaluates to null or would throw a NullError if evaluated.
Then, x.a.b.c ?: 'xxx' would return 'xxx' if any of the dereferenced fields were null.

@jaccomoc jaccomoc added the enhancement New feature or request label Nov 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant