Distpatch on keyword arguments

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

I mean

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

It’s been discussed for a long time but not implemented yet: Keyword arguments affect methods dispatch · Issue #9498 · JuliaLang/julia · GitHub

5 Likes

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

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)

I remember doing this once but now I can’t seem to find it. It really should be documented here.