-
-
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 the only(f, x)
method, which allows users to provide a default value or customize the error message
#44397
Conversation
I don't think that's what we decided on. I'm pretty sure we said this should behave mostly like |
Yes, we should just call Also, as discussed in #43491, I strongly believe we should stop introducing |
only(f::Function, x)
method, which allows users to customize the error messageonly(f::Function, x)
method, which allows users to provide a default value or customize the error message
only(f::Function, x)
method, which allows users to provide a default value or customize the error messagegetonly(f, x)
method, which allows users to provide a default value or customize the error message
5bdc044
to
9c1efaa
Compare
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.
Any reason to name this getonly
? I don't think we have any two-arg methods for only
yet, so keeping the name should be fine
Yeah, it was an intentional change. When I'm back at my computer, I'll write up my motivation for changing the name. |
I have removed the restriction that |
122d718
to
156f4c7
Compare
So what was the motivation? |
Whoops I completely forgot to reply. So, my thinking here is that the semantics of this new method seem sufficiently different from the semantics of the original For example, we currently have So I would say that |
It just seems weird to me to have two functions |
Maybe one can think about it like |
getonly(f, x)
method, which allows users to provide a default value or customize the error messageonly(f, x)
method, which allows users to provide a default value or customize the error message
FWIW, if we really want to derive composable and efficient error/"missing value" handling from a first principle, I believe CPS approach #43773 (reply in thread) I mentioned above is very attractive. For example, maybe it can be done by implementing otherwise(only, x) do _
f()
end for arbitrary Footnotes
|
That sounds like a much better approach to me, instead of having to do this manually for each function of interest. Want to make a PR showing what the implementation of |
I guess I can make a quick PR but it's almost surely going to cause discussion (for good reasons!) over months (or even years) so if you want to have it in the next minor bump, the best option is to ignore me 😉 So, I think the first step is to get triage's approval for #43773. But I'm not sure if we have arrived at a set of concrete decision points. For example, I don't think we have properly listed downsides of CPS (e.g., it's tedious and maybe too "infectious" to pass around continuation/effect manually; it's error-prone to enforce the return-as-is invariance manually; other languages go towards more implicit effect system and doing this manually may be too archaic in 2022). Until then, to avoid bitrotting PR, I think I'll be playing it within a package. I've been wanting to look into CPS in https://github.com/tkf/Try.jl. |
345f970
to
16266fa
Compare
I'm in no rush to get this in. I'd rather we come up with a general solution, then we can apply that to other functions ( |
39fd542
to
1cbec28
Compare
…value or customize the error message
1cbec28
to
f1fb37c
Compare
I'm suggesting using |
Closes #43729