Table of Contents

Class ResultExtensions

Namespace
Olve.Results
Assembly
Olve.Results.dll

Extension methods for Result and Result<T>.

public static class ResultExtensions
Inheritance
ResultExtensions
Inherited Members

Methods

Bind<TSource, TDestination>(Result<TSource>, Func<TSource, Result<TDestination>>)

Maps the value of a successful Result<T> using a function that itself returns a result.

public static Result<TDestination> Bind<TSource, TDestination>(this Result<TSource> result, Func<TSource, Result<TDestination>> bind)

Parameters

result Result<TSource>

The result to bind.

bind Func<TSource, Result<TDestination>>

The function to apply to the value, returning a new result.

Returns

Result<TDestination>

The result of the bind function, or the original problems on failure.

Type Parameters

TSource

The source value type.

TDestination

The destination value type.

Map<TSource, TDestination>(Result<TSource>, Func<TSource, TDestination>)

Maps the value of a successful Result<T> using the specified mapping function.

public static Result<TDestination> Map<TSource, TDestination>(this Result<TSource> result, Func<TSource, TDestination> map)

Parameters

result Result<TSource>

The result to map.

map Func<TSource, TDestination>

The function to apply to the value.

Returns

Result<TDestination>

A new result with the mapped value, or the original problems on failure.

Type Parameters

TSource

The source value type.

TDestination

The destination value type.

ToEmptyResult<T>(Result<T>)

Discards the value of a Result<T>, keeping only the success/failure status.

public static Result ToEmptyResult<T>(this Result<T> result)

Parameters

result Result<T>

The result to convert.

Returns

Result

A Result with the same success/failure status.

Type Parameters

T

The type of the discarded value.

WithValueOnSuccess<T>(Result, T)

Attaches a value to a successful Result, producing a Result<T>.

public static Result<T> WithValueOnSuccess<T>(this Result result, T value)

Parameters

result Result

The result to attach a value to.

value T

The value to attach on success.

Returns

Result<T>

A Result<T> with the value on success, or the original problems on failure.

Type Parameters

T

The type of the value.