Dispatching functions and keyword usage

Hi there,

Is there a way to dispatch on a function and still being able to call eventual keywords? I tried to dispatch a function, but could not call non-default keywords anymore afterwards.

MWE:

function testfn(a::Int64, b::Int64 , c::Int64; d = 5, e = 10)
    println( a + b + c)
    println(d)
    println(e)
end
testfn(1,2,3) # 6, 5, 10

#Now want to dispatch and keep keywords
testfn(c::Int64) = testfn(c, c, c)
testfn(1) #3, 5, 10

testfn(1; d = 1, e = 1) #MethodError: no method matching testfn(::Int64; d=1, e=1)

I would do something like

testfn(c::Int64; kwargs...) = testfn(c, c, c; kwargs...)
1 Like

Thank you, that works perfectly!