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

[FR] nothing-safe functions #42489

Closed
DhruvaSambrani opened this issue Oct 4, 2021 · 5 comments
Closed

[FR] nothing-safe functions #42489

DhruvaSambrani opened this issue Oct 4, 2021 · 5 comments

Comments

@DhruvaSambrani
Copy link

This is a proposal to define

nothing_safe(f, def=nothing) = x -> isnothing(x) ? def : f(x)

This would help in a lot of places where intermediate functions return nothing, such as regex matches, findfirst etc

@KristofferC
Copy link
Member

Isn't that pretty much just something(f(), def)?

@DhruvaSambrani
Copy link
Author

If I understand correctly, something will evaluate f() and then return def if the result of f is nothing. Here, I'd want to operate f on something that is possibly nothing

@oxinabox
Copy link
Contributor

oxinabox commented Oct 4, 2021

Semantically, this is the behavior that is considered desirable for missing (propagation),
and not desirable for nothing (should be solved when occurs, either by solving, erroring or changing to missing if context implies this (common for parsing))

@vtjnash
Copy link
Member

vtjnash commented Oct 4, 2021

Isn't that pretty much just ?

@something(f(), def) FTFY

This definition (for nothing_safe) is possibly also frequently known as lift, and is something we've discussed adding: #36628

@DhruvaSambrani
Copy link
Author

Close in favour of #36628

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants