Distpatch on keyword arguments


#1

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


#2

It’s been discussed for a long time but not implemented yet: https://github.com/JuliaLang/julia/issues/9498


#3

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)


#4

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