Result<T> struct
Namespace: Vitreous
Assembly: Vitreous.dll
Represents the outcome of a command or query that returns a value of type T.
This is a discriminated union: either a success value or an Error.
public readonly struct Result<T> : IEquatable<Result<T>>Type Parameters
Section titled “Type Parameters”T
The success value type.
Implements
Section titled “Implements”Inherited Members
Section titled “Inherited Members”object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()
Properties
Section titled “Properties”The failure error. For an uninitialized (default) result this is Uninitialized.
public Error Error { get; }Property Value
Section titled “Property Value”Exceptions
Section titled “Exceptions”Thrown when the result is a success.
IsFailure
Section titled “ IsFailure”Returns true when the result represents a failure.
public bool IsFailure { get; }Property Value
Section titled “Property Value”IsSuccess
Section titled “ IsSuccess”Returns true when the result represents a success.
public bool IsSuccess { get; }Property Value
Section titled “Property Value”The success value.
public T Value { get; }Property Value
Section titled “Property Value”T
Exceptions
Section titled “Exceptions”Thrown when the result is a failure.
Methods
Section titled “Methods”Bind<TOut>(Func<T, Result<TOut>>)
Section titled “ Bind<TOut>(Func<T, Result<TOut>>)”Chains a fallible projection using bind.
Returns the original failure unchanged if already failed.
public Result<TOut> Bind<TOut>(Func<T, Result<TOut>> bind)Parameters
Section titled “Parameters”Returns
Section titled “Returns”Result<TOut>
Type Parameters
Section titled “Type Parameters”TOut
BindAsync<TOut>(Func<T, ValueTask<Result<TOut>>>)
Section titled “ BindAsync<TOut>(Func<T, ValueTask<Result<TOut>>>)”Async variant of Bind<TOut>.
public ValueTask<Result<TOut>> BindAsync<TOut>(Func<T, ValueTask<Result<TOut>>> bind)Parameters
Section titled “Parameters”bind Func<T, ValueTask<Result<TOut>>>
Returns
Section titled “Returns”Type Parameters
Section titled “Type Parameters”TOut
Equals(Result<T>)
Section titled “ Equals(Result<T>)”Indicates whether the current object is equal to another object of the same type.
public bool Equals(Result<T> other)Parameters
Section titled “Parameters”other Result<T>
An object to compare with this object.
Returns
Section titled “Returns”true if the current object is equal to the other parameter; otherwise, false.
Equals(object?)
Section titled “ Equals(object?)”Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)Parameters
Section titled “Parameters”obj object?
The object to compare with the current instance.
Returns
Section titled “Returns”true if obj and this instance are the same type and represent the same value; otherwise, false.
Fail(Error)
Section titled “ Fail(Error)”Creates a failed result wrapping error.
public static Result<T> Fail(Error error)Parameters
Section titled “Parameters”error Error
Returns
Section titled “Returns”Result<T>
Exceptions
Section titled “Exceptions”Thrown when error is null.
GetHashCode()
Section titled “ GetHashCode()”Returns the hash code for this instance.
public override int GetHashCode()Returns
Section titled “Returns”A 32-bit signed integer that is the hash code for this instance.
Map<TOut>(Func<T, TOut>)
Section titled “ Map<TOut>(Func<T, TOut>)”Projects the success value using map.
Returns the original failure unchanged.
public Result<TOut> Map<TOut>(Func<T, TOut> map)Parameters
Section titled “Parameters”map Func<T, TOut>
Returns
Section titled “Returns”Result<TOut>
Type Parameters
Section titled “Type Parameters”TOut
MapAsync<TOut>(Func<T, ValueTask<TOut>>)
Section titled “ MapAsync<TOut>(Func<T, ValueTask<TOut>>)”Async variant of Map<TOut>.
public ValueTask<Result<TOut>> MapAsync<TOut>(Func<T, ValueTask<TOut>> map)Parameters
Section titled “Parameters”Returns
Section titled “Returns”Type Parameters
Section titled “Type Parameters”TOut
Match<TOut>(Func<T, TOut>, Func<Error, TOut>)
Section titled “ Match<TOut>(Func<T, TOut>, Func<Error, TOut>)”Executes onSuccess if the result is successful,
otherwise executes onFailure.
public TOut Match<TOut>(Func<T, TOut> onSuccess, Func<Error, TOut> onFailure)Parameters
Section titled “Parameters”onSuccess Func<T, TOut>
Returns
Section titled “Returns”TOut
Type Parameters
Section titled “Type Parameters”TOut
MatchAsync<TOut>(Func<T, ValueTask<TOut>>, Func<Error, ValueTask<TOut>>)
Section titled “ MatchAsync<TOut>(Func<T, ValueTask<TOut>>, Func<Error, ValueTask<TOut>>)”Async variant of Match<TOut>.
public ValueTask<TOut> MatchAsync<TOut>(Func<T, ValueTask<TOut>> onSuccess, Func<Error, ValueTask<TOut>> onFailure)Parameters
Section titled “Parameters”onSuccess Func<T, ValueTask<TOut>>
onFailure Func<Error, ValueTask<TOut>>
Returns
Section titled “Returns”ValueTask<TOut>
Type Parameters
Section titled “Type Parameters”TOut
Creates a successful result wrapping value.
public static Result<T> Ok(T value)Parameters
Section titled “Parameters”value T
Returns
Section titled “Returns”Result<T>
Exceptions
Section titled “Exceptions”Thrown when value is null.
A successful Result cannot hold a null value.
ToString()
Section titled “ ToString()”Returns the fully qualified type name of this instance.
public override string ToString()Returns
Section titled “Returns”The fully qualified type name.
Operators
Section titled “Operators”operator ==(Result<T>, Result<T>)
Section titled “ operator ==(Result<T>, Result<T>)”Returns true when both results are equal.
public static bool operator ==(Result<T> left, Result<T> right)Parameters
Section titled “Parameters”left Result<T>
right Result<T>
Returns
Section titled “Returns”implicit operator Result<T>(T)
Section titled “ implicit operator Result<T>(T)”Implicitly wraps a value as a successful result.
public static implicit operator Result<T>(T value)Parameters
Section titled “Parameters”value T
Returns
Section titled “Returns”Result<T>
implicit operator Result<T>(Error)
Section titled “ implicit operator Result<T>(Error)”Implicitly wraps an error as a failed result.
public static implicit operator Result<T>(Error error)Parameters
Section titled “Parameters”error Error
Returns
Section titled “Returns”Result<T>
operator !=(Result<T>, Result<T>)
Section titled “ operator !=(Result<T>, Result<T>)”Returns true when the results differ.
public static bool operator !=(Result<T> left, Result<T> right)Parameters
Section titled “Parameters”left Result<T>
right Result<T>