# Distpatch on keyword arguments

**URL:** <https://discourse.julialang.org/t/distpatch-on-keyword-arguments/10581>\
**Category:** General Usage\
**Created:** [April 27, 2018, 4:20pm UTC](https://discourse.julialang.org/t/distpatch-on-keyword-arguments/10581 "2018-04-27T16:20:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Iagoba\_Apellaniz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iagoba_apellaniz/32/34406_2.png) [@Iagoba\_Apellaniz](https://discourse.julialang.org/u/Iagoba_Apellaniz)\
**Post date:** [April 27, 2018, 4:20pm UTC](https://discourse.julialang.org/t/distpatch-on-keyword-arguments/10581/1 "2018-04-27T16:20:17Z")

</div>

Wouldn’t be possible to dispatch also on the keyword arguments?

I mean

```nohighlight
julia> foo(;x::Int = 0) = "Hello from Int x = $x kwarg"

julia> foo(;x::Float64 = 0.0) = "Hello from Float64 x = $x kwarg"

```

AFAIK, this would not break the language but extend its usability. If it has been discussed already, does anyone where? So, I would read and try tu understand the reasons it is not implemented.

Thanks

---

<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:** [April 27, 2018, 4:42pm UTC](https://discourse.julialang.org/t/distpatch-on-keyword-arguments/10581/2 "2018-04-27T16:42:04Z")

</div>

It’s been discussed for a long time but not implemented yet: [Keyword arguments affect methods dispatch · Issue #9498 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/9498)

---

<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:** [June 28, 2018, 4:10pm UTC](https://discourse.julialang.org/t/distpatch-on-keyword-arguments/10581/3 "2018-06-28T16:10:22Z")

</div>

The following occured to me with the new v0.7 features:

```julia
f(; kw...) = _f(kw.data)
_f(hasa::NamedTuple{(:a, )}) = (:a, hasa.a)
_f(hasb::NamedTuple{(:b, )}) = (:b, hasb.b)

```

(also, I wonder what the recommended API is for getting `kw` as a `NamedTuple` directly)

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [June 28, 2018, 4:50pm UTC](https://discourse.julialang.org/t/distpatch-on-keyword-arguments/10581/4 "2018-06-28T16:50:59Z")

</div>

> [@Tamas\_Papp](#):
>
> (also, I wonder what the recommended API is for getting `kw` as a `NamedTuple` directly)

I remember doing this once but now I can’t seem to find it. It really should be documented [here](https://docs.julialang.org/en/latest/manual/functions/#Keyword-Arguments-1).
