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 would be a parallel to the
fromMaybefunction inData.Maybein Haskell. The definition would be sorta like this:The usage / tests could be as follows:
Thoughts? Would a PR be accepted?