I’m looking for somemagicfunction
which behaves like
julia> somemagicfunction(::Type{typeof(one)}) = one
somemagicfunction (generic function with 1 method)
julia> somemagicfunction(typeof(one))
one (generic function with 12 methods)
but for arbitrary function (and without defining it manually as above).
Obviously I tried:
julia> typeof(one)()
ERROR: MethodError: no method matching typeof(one)()
FYI, the use-case is to use the function (object) in a trait like this:
julia> struct MyStruct{F}
f::F
end
julia> ExtractFun(::Type{MyStruct{F}}) where F = somemagicfunction(F)
ExtractFun (generic function with 1 method)
julia> ExtractFun(typeof(MyStruct(one)))
one (generic function with 12 methods)
I know that I can do Val{one}()
so maybe that’s the way to go. But keeping function in the field is very handy. I can put it both in the type parameter and the field but it feels redundant.