Skip to content

RFC: add a frommissing function #109

Description

@alhirzel

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions