Hi,
I was wondering if there is a way to dispatch on NamedTuple function arguments based on the types used within the NamedTuple without knowing the number of elements inside but with all elements having the same type.
So I would like to do something like this below:
function foo(nt::NamedTuple{Symbol, MyType})
println("The argument is a NamedTuple containing MyType elements")
end
function foo(nt::NamedTuple{Symbol, AnotherMyType})
println("The argument is a NamedTuple containing AnotherMyType elements")
end
So that
nt = (a = MyType(5), b = MyType(6), c = MyType(55))
nt2 = (x = AnotherMyType(2), y = AnotherMyType(3))
foo(nt)
The argument is a NamedTuple containing MyType elements
foot(nt2)
The argument is a NamedTuple containing AnotherMyType elements
Is there a better way to achieve this than doing something like this:
function foo(nt::NamedTuple)
if isa(foo[1], MyType)
println("The argument is a NamedTuple containing MyType elements")
elseif isa(foo[1], AnotherMyType)
println("The argument is a NamedTuple containing AnotherMyType elements")
end
end