Replies: 7 comments 1 reply
-
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 |
Beta Was this translation helpful? Give feedback.
-
I don't like the idea of adding syntactic overhead ( |
Beta Was this translation helpful? Give feedback.
-
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
|
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
I moved this to a discussion thread, since it does not have a specific feature or issue request, but is a good discussion to have |
Beta Was this translation helpful? Give feedback.
-
See also discussion here: https://julialang.zulipchat.com/#narrow/stream/137791-general/topic/Try.2Ejl |
Beta Was this translation helpful? Give feedback.
-
I don't want to hijack adkabo's thread on |
Beta Was this translation helpful? Give feedback.
-
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
#43149Beta Was this translation helpful? Give feedback.
All reactions