Result<T> constructor

Result<T>(T computation())

Creates a Result with the result of calling computation.

This generates either a ValueResult with the value returned by calling computation, or an ErrorResult with an error thrown by the call.

Implementation

factory Result(T computation()) {
  try {
    return new ValueResult<T>(computation());
  } catch (e, s) {
    return new ErrorResult(e, s);
  }
}