Keyword argument method without overwriting original method

julia> fun(x::Integer) = 1
fun (generic function with 1 method)

julia> fun(x::Integer; y::Array) = 1
fun (generic function with 1 method)

julia> fun(x::Integer, y::Array) = 1
fun (generic function with 2 methods)

Why doesn’t the 2nd definition create another method?
I know that I can make keyword optional by

julia> fun(x::Integer; y::Array= nothing) = 1
fun (generic function with 1 method)

But in my situation, I am expanding another function’s methods, and the function has fun(x::Integer) = 1 originally, and I don’t want to overwrite that method.

In the Slack group, It is pointed out that keyword arguments never participate in dispatch, and so there is no way other than redefining the original methods.

1 Like

If you need this you can try

https://github.com/simonbyrne/KeywordDispatch.jl

2 Likes

Oh thanks! That is a nice package!

I redefined the methods using metaprogramming, but this is a nice package to consider.
https://github.com/juliamatlab/MatLang/blob/5f391ab3a0f5e0846d8bfdc1afc6e45685ec412d/src/Language_Fundamentals/Matrices_and_Arrays.jl#L16-L116