Skip to main content

Result

Namespace: Bogoware.Monads

public static class Result

Inheritance ObjectResult
Attributes NullableContextAttribute, NullableAttribute

Properties

Unit

public static Result<Unit> Unit { get; }

Property Value

Result<Unit>

Methods

Success<TValue>(TValue)

Initializes a new successful instance of the Result<TValue> with the given value.

public static Result<TValue> Success<TValue>(TValue value)

Type Parameters

TValue

Parameters

value TValue

Returns

Result<TValue>

Failure<TValue>(String)

Initializes a new failed instance of the Result<TValue> with a LogicError with the message errorMessage.

public static Result<TValue> Failure<TValue>(string errorMessage)

Type Parameters

TValue

Parameters

errorMessage String

Returns

Result<TValue>

Failure<TValue>(Error)

Initializes a new failed instance of the Result<TValue> with the given error.

public static Result<TValue> Failure<TValue>(Error error)

Type Parameters

TValue

Parameters

error Error

Returns

Result<TValue>

Ensure(Boolean, Func<Error>)

If the condition is true then initializes a new successful instance of Result<TValue>, otherwise return a failed instance of Result<TValue> with the given error.

public static Result<Unit> Ensure(bool condition, Func<Error> error)

Parameters

condition Boolean

error Func<Error>

Returns

Result<Unit>

Ensure(Func<Boolean>, Func<Error>)

If the predicate evaluates to true then initializes a new successful instance of Result<TValue>, otherwise return a failed instance of Result<TValue> with the given error.

public static Result<Unit> Ensure(Func<bool> predicate, Func<Error> error)

Parameters

predicate Func<Boolean>

error Func<Error>

Returns

Result<Unit>

Ensure(Func<Task<Boolean>>, Func<Error>)

If the predicate evaluates to true then initializes a new successful instance of Result<TValue>, otherwise return a failed instance of Result<TValue> with the given error.

public static Task<Result<Unit>> Ensure(Func<Task<bool>> predicate, Func<Error> error)

Parameters

predicate Func<Task<Boolean>>

error Func<Error>

Returns

Task<Result<Unit>>

Bind<TValue>(Func<Result<TValue>>)

Initializes a new instance of the Result<TValue> with the value returned by result.

public static Result<TValue> Bind<TValue>(Func<Result<TValue>> result)

Type Parameters

TValue

Parameters

result Func<Result<TValue>>

Returns

Result<TValue>

Bind<TValue>(Func<Task<Result<TValue>>>)

Initializes a new instance of the Result<TValue> with the value returned by result.

public static Task<Result<TValue>> Bind<TValue>(Func<Task<Result<TValue>>> result)

Type Parameters

TValue

Parameters

result Func<Task<Result<TValue>>>

Returns

Task<Result<TValue>>

From<T>(T)

Initializes a new instance of the Result<TValue> with the value.

public static Result<T> From<T>(T value)

Type Parameters

T

Parameters

value T

Returns

Result<T>

Execute(Action)

Wraps the execution of the given action in a Result<TValue> catching any thrown exception and returning it as an RuntimeError .

public static Result<Unit> Execute(Action action)

Parameters

action Action

Returns

Result<Unit>

Execute(Func<Task>)

Wraps the execution of the given action in a Result<TValue> catching any thrown exception and returning it as an RuntimeError .

public static Task<Result<Unit>> Execute(Func<Task> action)

Parameters

action Func<Task>

Returns

Task<Result<Unit>>

Execute<TValue>(Func<TValue>)

Wraps the execution of the given function in a Result<TValue> catching any thrown exception and returning it as an RuntimeError .

public static Result<TValue> Execute<TValue>(Func<TValue> function)

Type Parameters

TValue

Parameters

function Func<TValue>

Returns

Result<TValue>

Execute<TValue>(Func<Task<TValue>>)

Wraps the execution of the given function in a Result<TValue> catching any thrown exception and returning it as an RuntimeError .

public static Task<Result<TValue>> Execute<TValue>(Func<Task<TValue>> function)

Type Parameters

TValue

Parameters

function Func<Task<TValue>>

Returns

Task<Result<TValue>>