Table of Contents

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

T

The type of the success value.

TError

The 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

bool

IsSuccess

Gets a value indicating whether this result holds a success value.

public bool IsSuccess { get; }

Property Value

bool

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

f Func<T, Result<TNext, TError>>

The function to apply to the success value.

Returns

Result<TNext, TError>

The result of f if this result is a success; otherwise the existing error propagated unchanged.

Type Parameters

TNext

The success type of the next result.

Fail(TError)

Creates a failed result wrapping error.

public static Result<T, TError> Fail(TError error)

Parameters

error TError

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

f Func<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

TNext

The mapped success type.

Ok(T)

Creates a successful result wrapping value.

public static Result<T, TError> Ok(T value)

Parameters

value T

Returns

Result<T, TError>