cfunction performs this sort of early method testing

although that's probably not quite what you want

i'm assuming your are using this for a callback, so the inflexible
interface makes sense. It sounds like you want a function type
declaration syntax. There's a low numbered issue to implement that
(since it can be used to give a speed boost to first-class function
arguments), but there haven't been any attempts to write the necessary
code AFAIK

On Tue, May 27, 2014 at 6:33 PM, Jacob Quinn <[email protected]> wrote:
> 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