Match a type or an instance of it

I want to write a function which can dispatch on the type as well as on an instance of it.

I tried the following:

struct mytype end
f(Union{Type{mytype},mytype}) = 42
f(mytype)
f(mytype())

Is there a better way of doing this?

I don’t see how it could get any simpler.

Note, however, that this is generally discouraged style.

2 Likes

Nice link. Thank you!