# Dispatching functions and keyword usage

**URL:** <https://discourse.julialang.org/t/dispatching-functions-and-keyword-usage/69825>\
**Category:** General Usage\
**Tags:** dispatch, keywords\
**Created:** [October 15, 2021, 1:07pm UTC](https://discourse.julialang.org/t/dispatching-functions-and-keyword-usage/69825 "2021-10-15T13:07:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrVeng](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mrveng/32/8836_2.png) [@mrVeng](https://discourse.julialang.org/u/mrVeng)\
**Post date:** [October 15, 2021, 1:07pm UTC](https://discourse.julialang.org/t/dispatching-functions-and-keyword-usage/69825/1 "2021-10-15T13:07:45Z")

</div>

Hi there,

Is there a way to dispatch on a function and still being able to call eventual keywords? I tried to dispatch a function, but could not call non-default keywords anymore afterwards.

MWE:

```julia
function testfn(a::Int64, b::Int64 , c::Int64; d = 5, e = 10)
    println( a + b + c)
    println(d)
    println(e)
end
testfn(1,2,3) # 6, 5, 10

#Now want to dispatch and keep keywords
testfn(c::Int64) = testfn(c, c, c)
testfn(1) #3, 5, 10

testfn(1; d = 1, e = 1) #MethodError: no method matching testfn(::Int64; d=1, e=1)

```

---

<div class="post-metadata">

**Author:** ![StevenWhitaker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevenwhitaker/32/9749_2.png) [@StevenWhitaker](https://discourse.julialang.org/u/StevenWhitaker)\
**Post date:** [October 15, 2021, 1:28pm UTC](https://discourse.julialang.org/t/dispatching-functions-and-keyword-usage/69825/2 "2021-10-15T13:28:57Z")

</div>

I would do something like

```julia
testfn(c::Int64; kwargs...) = testfn(c, c, c; kwargs...)

```

---

<div class="post-metadata">

**Author:** ![mrVeng](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mrveng/32/8836_2.png) [@mrVeng](https://discourse.julialang.org/u/mrVeng)\
**Post date:** [October 15, 2021, 1:37pm UTC](https://discourse.julialang.org/t/dispatching-functions-and-keyword-usage/69825/3 "2021-10-15T13:37:28Z")

</div>

> [@mrVeng](#):
>
> ```julia
> function testfn(a::Int64, b::Int64 , c::Int64; d = 5, e = 10)
> println( a + b + c)
> println(d)
> println(e)
> end
> testfn(1,2,3) # 6, 5, 10
> 
> #Now want to dispatch and keep keywords
> testfn(c::Int64) = testfn(c, c, c)
> testfn(1) #3, 5, 10
> 
> testfn(1; d = 1, e = 1) 
> 
> ```

Thank you, that works perfectly!
