Try<T> function
Implementation
Validation<T> Try<T>(T Function () tryBlock) {
try
{
return Valid<T>(tryBlock());
}
catch(e)
{
if(e is Error)
{
return Fail.withError(e).toInvalid<T>();
}
else if(e is Exception) {
return Fail.withException(e).toInvalid<T>();
}
return Fail.withError(Error(), message: 'Unknown error').toInvalid<T>();
}
}