I was recently super pleasantly surprised to discover the invoke
method,
invoke(f, types <: Tuple, args…)
Invoke a method for the given generic function matching the specified types, on the specified arguments. The arguments must be compatible with the specified types. This allows invoking a method other than the most specific matching method, which is useful when the behavior of a more general definition is explicitly needed (often as part of the implementation of a more specific method of the same function).
The thing in parentheses is exactly what I want to use invoke
for. Specifically, I’ve written some custom broadcast
method, inside of which I want to call the generic broadcast
that would have been used if my custom one didn’t exist. I could obviously check whatever this generic broadcast
is now, but I want something that works even if other definitions of broadcast
are added later.
So is there any programmatic way to figure our what this next-most-specific method would be and to invoke it?