Skip to content

Instantly share code, notes, and snippets.

@altbodhi
Created June 17, 2020 00:17
Show Gist options
  • Save altbodhi/b12173317e8b90152438ea03f2a518da to your computer and use it in GitHub Desktop.
Save altbodhi/b12173317e8b90152438ea03f2a518da to your computer and use it in GitHub Desktop.
public abstract class Result<TValue, TError>
{
public bool IsOk => this is Ok;
public sealed class Ok : Result<TValue, TError>
{
public TValue Value { get; }
internal Ok(TValue value) => Value = value;
}
public sealed class Err : Result<TValue, TError>
{
public TError Error { get; }
internal Err(TError error) => Error = error;
}
public static Result<TValue, TError> NewErr(TError error) => new Err(error);
public static Result<TValue, TError> NewOk(TValue value) => new Ok(value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment