/ResultPatternExample

Result-Pattern example with implicit conversion and Match function.

Primary LanguageC#

Result-Pattern Example

  • Implicit conversion of Values and Errors to 'Result' objects:
  public static implicit operator Result(TValue value) => new(value);
  public static implicit operator Result(Error error) => new(error);
  • 'Match' function for handling the Result object:
  public TResult Match(
      Func success,
      Func failure)
  {
      return _isSuccess
          ? success(_value!)
          : failure(_error);
  }