More generic type checking for custom function return