How can kwargs be used in multiple dispatch

Kwargs do not differentiate methods, so the Int version was overwritten (note the 1 method after the second definition).

I use this approach, in cases like this:

_f(a, b::Int) = 1
_f(a, c::Real) = 2
function f(a; b = nothing, c = nothing)
    !isnothing(b) && return _f(a,b)
    !isnothing(c) && return _f(a,c)
end

But I’m not a fan of it. Other opinions are welcome.

3 Likes