Struct Result<T, TError>
- Namespace
- ShadowDusk.Core
- Assembly
- ShadowDusk.Core.dll
A lightweight discriminated union representing either a success value of type
T or an error of type TError. ShadowDusk
uses this instead of exception-as-control-flow: compilation outcomes are returned, not
thrown.
public readonly struct Result<T, TError>
Type Parameters
TThe type of the success value.
TErrorThe type of the error value.
- Inherited Members
Properties
Error
Gets the error value. Throws InvalidOperationException if this result is a success — check IsFailure first.
public TError Error { get; }
Property Value
- TError
IsFailure
Gets a value indicating whether this result holds an error.
public bool IsFailure { get; }
Property Value
IsSuccess
Gets a value indicating whether this result holds a success value.
public bool IsSuccess { get; }
Property Value
Value
Gets the success value. Throws InvalidOperationException if this result is a failure — check IsSuccess first.
public T Value { get; }
Property Value
- T
Methods
Bind<TNext>(Func<T, Result<TNext, TError>>)
Chains another fallible operation onto a success value, short-circuiting on failure.
public Result<TNext, TError> Bind<TNext>(Func<T, Result<TNext, TError>> f)
Parameters
Returns
- Result<TNext, TError>
The result of
fif this result is a success; otherwise the existing error propagated unchanged.
Type Parameters
TNextThe success type of the next result.
Fail(TError)
Creates a failed result wrapping error.
public static Result<T, TError> Fail(TError error)
Parameters
errorTError
Returns
- Result<T, TError>
Map<TNext>(Func<T, TNext>)
Transforms a success value, leaving a failure untouched.
public Result<TNext, TError> Map<TNext>(Func<T, TNext> f)
Parameters
fFunc<T, TNext>The projection to apply to the success value.
Returns
- Result<TNext, TError>
A success wrapping
f(value)if this result is a success; otherwise the existing error propagated unchanged.
Type Parameters
TNextThe mapped success type.
Ok(T)
Creates a successful result wrapping value.
public static Result<T, TError> Ok(T value)
Parameters
valueT
Returns
- Result<T, TError>