Missings.jl
Missings.jl copied to clipboard
RFC: add a `frommissing` function
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?
This exists in Base as coalesce(value, default)
.