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

RFC: add a frommissing function #109

Open
alhirzel opened this issue Oct 13, 2019 · 1 comment
Open

RFC: add a frommissing function #109

alhirzel opened this issue Oct 13, 2019 · 1 comment

Comments

@alhirzel
Copy link

alhirzel commented Oct 13, 2019

This would be a parallel to the fromMaybe function in Data.Maybe in Haskell. The definition would be sorta like this:

frommissing(default::T, value::Union{Missing, T}) where {T} = ismissing(value) ? default : value

The usage / tests could be as follows:

@test frommissing(4, missing) == 4
@test frommissing(4, 10) == 10
@test_throws MethodError frommissing(4, 10.0) # type mismatch
@test frommissing.(4, [missing, 10]) == [4, 10]

Thoughts? Would a PR be accepted?

@alhirzel alhirzel changed the title RFC: add a function frommissing function RFC: add a frommissing function Oct 13, 2019
@ararslan
Copy link
Member

This exists in Base as coalesce(value, default).

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

2 participants