# Is there a standard way to add missing-propagation

**URL:** <https://discourse.julialang.org/t/is-there-a-standard-way-to-add-missing-propagation/36727>\
**Category:** General Usage\
**Created:** [March 30, 2020, 10:02am UTC](https://discourse.julialang.org/t/is-there-a-standard-way-to-add-missing-propagation/36727 "2020-03-30T10:02:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [March 30, 2020, 10:02am UTC](https://discourse.julialang.org/t/is-there-a-standard-way-to-add-missing-propagation/36727/1 "2020-03-30T10:02:16Z")

</div>

By “add missing-propagation,” I mean making a function return missing if any one of its arguments is missing. So far the few times I wanted to do that, I add a one-liner method for each argument as type Missing, like so:

> blah(x, y, z) = “blah” # example function  
> #added functions:  
> blah(x::Missing, y, z) = missing  
> blah(x, y::Missing, z) = missing  
> blah(x, y, z::Missing) = missing

You can see that can get tedious the more arguments a function has. I’m wondering if there’s some standard one-liner way to do this.  
If not, I might get around to learning how to write macros. I’d be really thankful for tips like how to inspect existing methods for their number and names of arguments and how to define multiple nearly identical methods in a macro.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 30, 2020, 11:29am UTC](https://discourse.julialang.org/t/is-there-a-standard-way-to-add-missing-propagation/36727/2 "2020-03-30T11:29:22Z")

</div>

There is [`Missings.passmissing`](https://github.com/JuliaData/Missings.jl/blob/7e5cd9f31600fbb3d478ba79e593fd67ca954ad2/src/Missings.jl#L181) as a wrapper, but also note that

```julia
function blah(x, y, z)
    if any(ismissing, (x, y, z))
        missing
    else
        "blah"
    end
end

```

also compiles to efficient code.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [March 30, 2020, 2:48pm UTC](https://discourse.julialang.org/t/is-there-a-standard-way-to-add-missing-propagation/36727/3 "2020-03-30T14:48:02Z")

</div>

> [@Benny](#):
>
> If not, I might get around to learning how to write macros. I’d be really thankful for tips like how to inspect existing methods for their number and names of arguments and how to define multiple nearly identical methods in a macro.

This could be a nice case for a macro, but I wouldn’t make it as complex as you’re suggesting. Instead, you could write a macro that makes use of the `passmissing` function that @Tamas_Papp suggested. For example, given a function like:

```julia
julia> function f(a, b, c)
         a + b + c
       end

```

You could write a macro that instead produces this code:

```julia
 julia> function f(a, b, c)
         passmissing(function f(a, b, c)
           a + b + c
         end)(a, b, c)
       end

```

which gives:

```julia
julia> f(1, 2, 3)
6

julia> f(1, 2, missing)
missing

julia> f(missing, 2, 3)
missing

```

This looks a bit weird, but all I’m doing is passing the original function definition to `passmissing` and then calling the result on the arguments `(a, b, c)`. The nice thing about this is that the transformation from the original function syntax to the modified one should be easy to do programmatically (and thus this is a good case for a macro).
