I have a function that has some default keyword arguments, and operates on an abstract type that I have defined e.g
f(a::A;kw=default)=#stuff
I would now like to specify this method with a type B<:A , without actually affecting the function itself just changing the default kwarg:
f(b::B;kw=anotherDefault)=#same stuff
Ideally I don't need to copy the body of the function..
you could either do something like
f(a::T; kw = T === A ? default : anotherDefault) where T <: Union{A,B}
or put the actual implementation into a different method
f(a::A;kw=default) = _f(a, kw)
f(a::B;kw=anotherDefault) = _f(a, kw)
_f(a, kw) = ...
Last updated: Nov 06 2024 at 04:40 UTC