I am doing a small experiment in dart and I couldn't find a way to determine if a variable is "callable" without explicitly checking for each type (String, int, bool, ect) and guessing that it was callable if it was none of those. I also experimented with a try/catch which to me just seems wrong.
Whats the right way or at least the best way to make that determination?
Here is an example I did to show what I am trying to accomplish: https://gist.github.com/digitalfiz/3f431dc07ca761389062
Use this function:
bool isCallable(v) => v is Function;
Usage Examples:
class Callable {
call() => 42;
}
void main() {
var foo = () => 42;
var bar = new Callable();
var baz = 42;
print(isCallable(foo)); //true
print(isCallable(bar)); //true
print(isCallable(baz)); //false
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With