ErrorCheckerFunc(fn myFunc, message){
returnVal, returnError = myFunc();
switchError:
case error is foo:
print error
case error is bar:
log error print "error logged"
...
case n+1 etc
// you can handle message in a similar way to get
// cases by function names, and if you have elixir
// style quote unquote metaprogramming in Golang you might just be able to get function names based on passed function - I don't think this is in the language spec though it may be possible to do some other way.
if error not nil do switchError(error)
return RuhRoh
else
return returnVal
}
I'm not clear on what exactly you're trying to represent here, but it looks like something that wouldn't work with Go's type system. ErrorCheckerFunc would need to always have the same return type and accept a function with the same type signature.
If only there was a way to make a single function work with multiple different types. A way to "genericize" it, you might say.
Alas, that's obviously completely impossible. Such a thing is beyond the capabilities of us mortal programmers. But maybe one day PL researchers will discover a way. One day...