-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Define maybeparse(T,x)::Union{Nothing,Some{T}} #43686
Comments
An alternative solution which would fit better with the current API would be to write EDIT: see also #29565 where we need a syntax to call |
I don't like the idea of adding syntactic overhead ( |
I've been wondering about something similar but a bit generalized version: Can we have a consistent convention/API for We have the
I don't think this can work if we want to make it possible to generalize Footnotes
|
First, let me say that I am completely, totally on board with having a concerted effort to create a well-thought out system for result types in Julia. These kinds of systems are great in any language, but Julia seems to be uniquely suitable for creating a nice result type system due to its type system. The current situation with With regard to a naming scheme for failable functions, I would prefer using type annotation on functions for this instead of a naming convention. Not only are type asserts easy to read and do not introduce new syntax or concepts, they actually assert that the function returns a result type instead of just suggesting it. Further, they can optionally say exactly which result type. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Background
A number of functions in Base and packages return
T
ornothing
, often written before Julia hadSome{T}
. Callers of these functions are not always able to tell whether the computation failed or successfully returned a value ofnothing
.Proposal
I want to use this pattern:
tryparse
doesn't wrap the successful value inSome
.maybeparse
would do so and would be a replacement for that function to be recommended in new code.This function isn't strictly necessary since we already can distinguish using
try parse(T,x) catch
but it would be nice to have an exceptionless version that can be used in expression contexts like pattern matching.Naming
maybeparse
is a bit long so it could bemayparse
.References
get
WIP/RFC: add 2-argumentget
returningUnion{Nothing,Some}
#34821maybetake!
add maybetake! and tryput! #41966 by @tkffindfirst
findfirst
on dictionaries returns ambiguous result #29565 (Mentioned in comment below.)tryparse
issue Defineparse
in terms oftryparse
#43149The text was updated successfully, but these errors were encountered: