Core Concepts — Result, Error, Maybe & Generic
Understanding the memory layout and state machine of Result, Result<TValue>, and Error ensures predictable behavior across synchronous pipelines and default-struct boundaries.
| Type | Package | Purpose |
|---|---|---|
Result |
EricksonLopez.Result |
Non-generic outcome (Success or Failure(Error)); implements IResultOutcome, IResultFactory<Result> |
Result<TValue> |
EricksonLopez.Result |
Generic readonly struct holding TValue or Error |
Result<TValue, TError> |
EricksonLopez.Result.Generic |
Custom strongly-typed error TError with .IsUninitialized and .ToResult(...) |
Maybe<T> |
EricksonLopez.Result.Maybe |
Optional value wrapper convertible via Maybe<T>.From(entity).ToResult(error) |
Error is a sealed partial class exposing semantic factories mapped to ErrorType and default ErrorSeverity:
Error.Validation(code, desc)→ErrorType.ValidationError.NotFound(code, desc)/Error.NotFound<TId>(code, id)→ErrorType.NotFoundError.Conflict(code, desc)→ErrorType.ConflictError.Unauthorized(code, desc)/Error.Forbidden(code, desc)→Unauthorized/ForbiddenError.Domain(code, desc)/Error.Business(code, desc)→ErrorType.DomainError.Unavailable(code, desc)/Error.Infrastructure(code, desc)→ transient infrastructure faultsError.Failure(code, desc)/Error.Unexpected(code, desc)→ general or critical failuresError.Create(code, desc)→ returnsErrorBuilderfor custom metadata/inner errors
Because C# allows default(Result) and default(Result<TValue>) on structs, v3.0.0 enforces strict uninitialized semantics:
default(Result<TValue>).IsSuccessanddefault(Result<TValue>).IsFailureare bothfalse(TryGetErrorreturnsfalse,ToString()returns"Uninitialized").Result.CombineandResult.ValidateAllreject uninitialized inputs instead of silently treatingdefaultas success.WellKnownErrors.UninitializedErrorsurfaces the diagnostic error when uninitialized structs are unwrapped or converted (Result(in Result<TValue>)).