-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Add generic isnull and unsafe_get methods #18484
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1324,6 +1324,7 @@ export | |
|
||
# nullable types | ||
isnull, | ||
unsafe_get, | ||
|
||
# Macros | ||
# parser internal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,68 @@ end | |
|
||
get(x::Nullable) = isnull(x) ? throw(NullException()) : x.value | ||
|
||
""" | ||
unsafe_get(x) | ||
Return the value of `x` for [`Nullable`](:obj:`Nullable`) `x`; return `x` for | ||
all other `x`. | ||
This method does not check whether or not `x` is null before attempting to | ||
access the value of `x` for `x::Nullable` (hence "unsafe"). | ||
```jldoctest | ||
julia> x = Nullable(1) | ||
Nullable{Int64}(1) | ||
julia> unsafe_get(x) | ||
1 | ||
julia> x = Nullable{String}() | ||
Nullable{String}() | ||
julia> unsafe_get(x) | ||
ERROR: UndefRefError: access to undefined reference | ||
in unsafe_get(::Nullable{String}) at ./REPL[4]:1 | ||
julia> x = 1 | ||
1 | ||
julia> unsafe_get(x) | ||
1 | ||
``` | ||
""" | ||
unsafe_get(x::Nullable) = x.value | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs a docstring. |
||
unsafe_get(x) = x | ||
|
||
""" | ||
isnull(x) | ||
Return whether or not `x` is null for [`Nullable`](:obj:`Nullable`) `x`; return | ||
`false` for all other `x`. | ||
```jldoctest | ||
julia> x = Nullable(1, false) | ||
Nullable{Int64}(1) | ||
julia> isnull(x) | ||
false | ||
julia> x = Nullable(1, true) | ||
Nullable{Int64}() | ||
julia> isnull(x) | ||
true | ||
julia> x = 1 | ||
1 | ||
julia> isnull(x) | ||
false | ||
``` | ||
""" | ||
isnull(x::Nullable) = x.isnull | ||
isnull(x) = false | ||
|
||
isnull(x::Nullable) = !x.hasvalue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bad rebase |
||
|
||
## Operators | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just being curious, do we need this to get links?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's my understanding. @kshyatt included these in https://github.com/JuliaLang/julia/pull/18511/files#diff-1955b2684af6e5a407aa36281f8bafdeR94, so I figured I'd include them here, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this documented somewhere? Maybe somebody could add a word about this at http://docs.julialang.org/en/latest/manual/documentation/? @MichaelHatherly
(FWIW, the repetition of the object name sounds a bit annoying to me...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That syntax is being removed in #18588 in favour of
[
Nullable](@ref)
, so probably no need to add it to the docs at this point.We can never have too many cross references 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I'll remove the references for now. I think we will all live with the repetition in the docstring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does the auto conversion script translate them from the current rst-in-markdown hybrid to the new style? if so it won't hurt to add if this gets merged before the conversion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, handled automatically. It's fine to keep adding xrefs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I will add it back in.