# Functions as keyword arguments

**URL:** <https://discourse.julialang.org/t/functions-as-keyword-arguments/63983>\
**Category:** General Usage\
**Created:** [July 3, 2021, 11:18am UTC](https://discourse.julialang.org/t/functions-as-keyword-arguments/63983 "2021-07-03T11:18:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [July 3, 2021, 11:18am UTC](https://discourse.julialang.org/t/functions-as-keyword-arguments/63983/1 "2021-07-03T11:18:19Z")

</div>

This function is to be called either without an auxiliary function or with one. But how can you test the supplied keyword argument to know when an auxiliary function has been supplied?

```julia
function f(a; func = (b, c) -> ())
    if ??? 
        println("default")
    else
        println("custom")
    end 
end

auxfunction(b, c) = println(b, c)

f(42)

f(42; func = auxfunction)

```

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [July 3, 2021, 11:33am UTC](https://discourse.julialang.org/t/functions-as-keyword-arguments/63983/2 "2021-07-03T11:33:07Z")

</div>

A common pattern is just to use `nothing` as a placeholder:

```julia
function f(a; func = nothing)
    if func === nothing
        func = (b, c) -> () 
        println("default")
    else
        println("custom")
    end 
end

```

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [July 3, 2021, 12:54pm UTC](https://discourse.julialang.org/t/functions-as-keyword-arguments/63983/3 "2021-07-03T12:54:58Z")

</div>

Yes, that works great - thanks!
