In a function that takes a function as argument, it is clear how to provide a method specific to a named function (e.g. in by using ::Base.Fix2{typeof(in),T}). But it is unclear to me how to do the same thing for !in. If I make a method with signature ::Base.Fix2{typeof(!in),T}, it is never called. In code:
julia> struct A end;
julia> g(::Base.Fix2{typeof(in),A}) = nothing;
julia> g(::Base.Fix2{typeof(!in),A}) = nothing;
julia> g(in(A()))
julia> g(!in(A()))
ERROR: MethodError: no method matching g(::getfield(Base, Symbol("##54#55")){Base.Fix2{typeof(in),A}})
Closest candidates are:
g(::Base.Fix2{getfield(Base, Symbol("##54#55")){typeof(in)},A}) at REPL[3]:1
g(::Base.Fix2{typeof(in),A}) at REPL[2]:1
Stacktrace:
[1] top-level scope at none:0
Good question. My goal has been to fill out all the methods of UniqueVectors with the most efficient versions possible. I noticed, though, that the !in method was not being called, despite me defining it; hence the question here. Examining this more, though, this method is actually no better than the fallback, so itβs completely unnecessary.
Then again, in Base it might be desirable to define an override method for findall for !in, just as there is currently one for in. I have no specific use for this method at the moment, but it seems useful and could be implemented more efficiently than the current fallback method (which performs linear search in the predicate for each element of the array being searched).
My understanding is that such a method could be defined already, dispatching on typeof(!in).
It is true that !!in would fail to call the method the method for in, and your proposal would remedy that. But instead, it would be better if !(!f) === f was implemented in general.