I'm thinking there's probably a better way to do this.

For some date-related stuff, I have a method that needs to take an 
"inclusion" function as an argument and I'm wondering what the best way to 
validate that the user has supplied a correctly formed "inclusion" 
function. The requirements are that the provided function, either generic 
or anonymous, take a single TimeType argument and return a Bool. So

ismonday(x::TimeType) = dayofweek(x) == Monday

and

x->dayofweek(x)==Monday

Are both valid functions to pass to my method, but what's the best way to 
validate? I looked at `applicable`, but it's for generics only. For now I'm 
just doing:

func(T(0)) in (true,false) || throw(ArgumentError("Provided function must 
take a single TimeType argument and return true or false"))

where `func` is the user-provided inclusion function and `T` is the 
TimeType we're dealing with. The main problem is if a 2-arg method is 
supplied, I get a wrong number of args error and I'd rather not have to use 
try-catch.

Any ideas? Something more clever?

-Jacob

Reply via email to