Table of Contents

Struct Result

Namespace
Olve.Results
Assembly
Olve.Results.dll

Represents a result of an operation without a value, indicating success or failure.

public readonly struct Result
Inherited Members
Extension Methods

Properties

Failed

Gets a value indicating whether the operation failed.

public bool Failed { get; }

Property Value

bool

Problems

Gets the collection of problems associated with the result, if any.

public ResultProblemCollection? Problems { get; }

Property Value

ResultProblemCollection

Succeeded

Gets a value indicating whether the operation succeeded.

public bool Succeeded { get; }

Property Value

bool

Methods

Chain(params IEnumerable<Func<Result>>)

Executes a sequence of functions that return a Result. If any function in the chain returns a result containing problems, execution stops, and that result is returned. Otherwise, returns a successful result.

public static Result Chain(params IEnumerable<Func<Result>> links)

Parameters

links IEnumerable<Func<Result>>

An array of functions that return a Result.

Returns

Result

The first result with problems, or a successful result if all functions succeed.

Chain<T1, T2>(Func<Result<T1>>, Func<T1, Result<T2>>)

Chains two result-producing functions, returning a combined result if both succeed.

public static Result<T2> Chain<T1, T2>(Func<Result<T1>> a, Func<T1, Result<T2>> b)

Parameters

a Func<Result<T1>>

The first function that produces a result.

b Func<T1, Result<T2>>

The second function that produces a result.

Returns

Result<T2>

The result of the second function if both succeed; otherwise, the first encountered problem.

Type Parameters

T1

The type of the first result value.

T2

The type of the second result value.

Chain<T1, T2, T3>(Func<Result<T1>>, Func<T1, Result<T2>>, Func<T2, Result<T3>>)

Chains three result-producing functions, returning a combined result if all succeed.

public static Result<T3> Chain<T1, T2, T3>(Func<Result<T1>> a, Func<T1, Result<T2>> b, Func<T2, Result<T3>> c)

Parameters

a Func<Result<T1>>

The first function that produces a result.

b Func<T1, Result<T2>>

The second function that produces a result.

c Func<T2, Result<T3>>

The third function that produces a result.

Returns

Result<T3>

The result of the third function if all succeed; otherwise, the first encountered problem.

Type Parameters

T1

The type of the first result value.

T2

The type of the second result value.

T3

The type of the third result value.

Chain<T1, T2, T3, T4>(Func<Result<T1>>, Func<T1, Result<T2>>, Func<T2, Result<T3>>, Func<T3, Result<T4>>)

Chains four result-producing functions, returning a combined result if all succeed.

public static Result<T4> Chain<T1, T2, T3, T4>(Func<Result<T1>> a, Func<T1, Result<T2>> b, Func<T2, Result<T3>> c, Func<T3, Result<T4>> d)

Parameters

a Func<Result<T1>>

The first function that produces a result.

b Func<T1, Result<T2>>

The second function that produces a result.

c Func<T2, Result<T3>>

The third function that produces a result.

d Func<T3, Result<T4>>

The fourth function that produces a result.

Returns

Result<T4>

The result of the fourth function if all succeed; otherwise, the first encountered problem.

Type Parameters

T1

The type of the first result value.

T2

The type of the second result value.

T3

The type of the third result value.

T4

The type of the fourth result value.

Concat(params IEnumerable<Result>)

Concatenates a sequence of results.

public static Result Concat(params IEnumerable<Result> results)

Parameters

results IEnumerable<Result>

The results.

Returns

Result

A successful result if all functions succeed; otherwise, all encountered problems.

Concat(params IEnumerable<Func<Result>>)

Concatenates a sequence of functions that produce results.

public static Result Concat(params IEnumerable<Func<Result>> elements)

Parameters

elements IEnumerable<Func<Result>>

The functions that produce results.

Returns

Result

A successful result if all functions succeed; otherwise, all encountered problems.

Concat<T1, T2>(Result<T1>, Result<T2>)

Concatenates two Result<T> values into a tuple if both succeed, or aggregates all problems if one or both fail.

public static Result<(T1, T2)> Concat<T1, T2>(Result<T1> a, Result<T2> b)

Parameters

a Result<T1>

The first Result<T> value.

b Result<T2>

The second Result<T> value.

Returns

Result<(T1, T2)>

A Result<T> containing a tuple of the two values if both succeeded; otherwise a ResultProblemCollection containing all validation problems.

Type Parameters

T1

The type of the first result value.

T2

The type of the second result value.

Concat<T1, T2>(Func<Result<T1>>, Func<Result<T2>>)

Invokes two functions that produce Result<T> values and concatenates them into a tuple by delegating to the non‑Func Concat<T1, T2>(Result<T1>, Result<T2>) overload.

public static Result<(T1, T2)> Concat<T1, T2>(Func<Result<T1>> a, Func<Result<T2>> b)

Parameters

a Func<Result<T1>>

A function that produces the first Result<T>.

b Func<Result<T2>>

A function that produces the second Result<T>.

Returns

Result<(T1, T2)>

A Result<T> containing a tuple of the two values if both succeeded; otherwise a ResultProblemCollection containing all aggregated problems.

Type Parameters

T1

The type of the first result value.

T2

The type of the second result value.

Concat<T1, T2, T3>(Result<T1>, Result<T2>, Result<T3>)

Concatenates three Result<T> values into a tuple if all succeed, or aggregates all problems if any fail.

public static Result<(T1, T2, T3)> Concat<T1, T2, T3>(Result<T1> a, Result<T2> b, Result<T3> c)

Parameters

a Result<T1>

The first Result<T> value.

b Result<T2>

The second Result<T> value.

c Result<T3>

The third Result<T> value.

Returns

Result<(T1, T2, T3)>

A Result<T> containing a tuple of the three values if all succeeded; otherwise a ResultProblemCollection containing all validation problems.

Type Parameters

T1

The type of the first result value.

T2

The type of the second result value.

T3

The type of the third result value.

Concat<T1, T2, T3>(Func<Result<T1>>, Func<Result<T2>>, Func<Result<T3>>)

Invokes three functions that produce Result<T> values and concatenates them into a tuple by delegating to the non‑Func Concat<T1, T2, T3>(Result<T1>, Result<T2>, Result<T3>) overload.

public static Result<(T1, T2, T3)> Concat<T1, T2, T3>(Func<Result<T1>> a, Func<Result<T2>> b, Func<Result<T3>> c)

Parameters

a Func<Result<T1>>

A function that produces the first Result<T>.

b Func<Result<T2>>

A function that produces the second Result<T>.

c Func<Result<T3>>

A function that produces the third Result<T>.

Returns

Result<(T1, T2, T3)>

A Result<T> containing a tuple of the three values if all succeeded; otherwise a ResultProblemCollection containing all aggregated problems.

Type Parameters

T1

The type of the first result value.

T2

The type of the second result value.

T3

The type of the third result value.

Concat<T1, T2, T3, T4>(Result<T1>, Result<T2>, Result<T3>, Result<T4>)

Concatenates four Result<T> values into a tuple if all succeed, or aggregates all problems if any fail.

public static Result<(T1, T2, T3, T4)> Concat<T1, T2, T3, T4>(Result<T1> a, Result<T2> b, Result<T3> c, Result<T4> d)

Parameters

a Result<T1>

The first Result<T> value.

b Result<T2>

The second Result<T> value.

c Result<T3>

The third Result<T> value.

d Result<T4>

The fourth Result<T> value.

Returns

Result<(T1, T2, T3, T4)>

A Result<T> containing a tuple of the four values if all succeeded; otherwise a ResultProblemCollection containing all validation problems.

Type Parameters

T1

The type of the first result value.

T2

The type of the second result value.

T3

The type of the third result value.

T4

The type of the fourth result value.

Concat<T1, T2, T3, T4>(Func<Result<T1>>, Func<Result<T2>>, Func<Result<T3>>, Func<Result<T4>>)

Invokes four functions that produce Result<T> values and concatenates them into a tuple by delegating to the non‑Func Concat<T1, T2, T3, T4>(Result<T1>, Result<T2>, Result<T3>, Result<T4>) overload.

public static Result<(T1, T2, T3, T4)> Concat<T1, T2, T3, T4>(Func<Result<T1>> a, Func<Result<T2>> b, Func<Result<T3>> c, Func<Result<T4>> d)

Parameters

a Func<Result<T1>>

A function that produces the first Result<T>.

b Func<Result<T2>>

A function that produces the second Result<T>.

c Func<Result<T3>>

A function that produces the third Result<T>.

d Func<Result<T4>>

A function that produces the fourth Result<T>.

Returns

Result<(T1, T2, T3, T4)>

A Result<T> containing a tuple of the four values if all succeeded; otherwise a ResultProblemCollection containing all aggregated problems.

Type Parameters

T1

The type of the first result value.

T2

The type of the second result value.

T3

The type of the third result value.

T4

The type of the fourth result value.

Concat<T1, T2, T3, T4, T5>(Result<T1>, Result<T2>, Result<T3>, Result<T4>, Result<T5>)

Concatenates five Result<T> values into a tuple if all succeed, or aggregates all problems if any fail.

public static Result<(T1, T2, T3, T4, T5)> Concat<T1, T2, T3, T4, T5>(Result<T1> a, Result<T2> b, Result<T3> c, Result<T4> d, Result<T5> e)

Parameters

a Result<T1>

The first Result<T> value.

b Result<T2>

The second Result<T> value.

c Result<T3>

The third Result<T> value.

d Result<T4>

The fourth Result<T> value.

e Result<T5>

The fifth Result<T> value.

Returns

Result<(T1, T2, T3, T4, T5)>

A Result<T> containing a tuple of the five values if all succeeded; otherwise a ResultProblemCollection containing all validation problems.

Type Parameters

T1

The type of the first result value.

T2

The type of the second result value.

T3

The type of the third result value.

T4

The type of the fourth result value.

T5

The type of the fifth result value.

Concat<T1, T2, T3, T4, T5>(Func<Result<T1>>, Func<Result<T2>>, Func<Result<T3>>, Func<Result<T4>>, Func<Result<T5>>)

Invokes five functions that produce Result<T> values and concatenates them into a tuple by delegating to the non‑Func Concat<T1, T2, T3, T4, T5>(Result<T1>, Result<T2>, Result<T3>, Result<T4>, Result<T5>) overload.

public static Result<(T1, T2, T3, T4, T5)> Concat<T1, T2, T3, T4, T5>(Func<Result<T1>> a, Func<Result<T2>> b, Func<Result<T3>> c, Func<Result<T4>> d, Func<Result<T5>> e)

Parameters

a Func<Result<T1>>

A function that produces the first Result<T>.

b Func<Result<T2>>

A function that produces the second Result<T>.

c Func<Result<T3>>

A function that produces the third Result<T>.

d Func<Result<T4>>

A function that produces the fourth Result<T>.

e Func<Result<T5>>

A function that produces the fifth Result<T>.

Returns

Result<(T1, T2, T3, T4, T5)>

A Result<T> containing a tuple of the five values if all succeeded; otherwise a ResultProblemCollection containing all aggregated problems.

Type Parameters

T1

The type of the first result value.

T2

The type of the second result value.

T3

The type of the third result value.

T4

The type of the fourth result value.

T5

The type of the fifth result value.

Concat<T1, T2, T3, T4, T5, T6>(Result<T1>, Result<T2>, Result<T3>, Result<T4>, Result<T5>, Result<T6>)

Concatenates six Result<T> values into a tuple if all succeed, or aggregates all problems if any fail.

public static Result<(T1, T2, T3, T4, T5, T6)> Concat<T1, T2, T3, T4, T5, T6>(Result<T1> a, Result<T2> b, Result<T3> c, Result<T4> d, Result<T5> e, Result<T6> f)

Parameters

a Result<T1>

The first Result<T> value.

b Result<T2>

The second Result<T> value.

c Result<T3>

The third Result<T> value.

d Result<T4>

The fourth Result<T> value.

e Result<T5>

The fifth Result<T> value.

f Result<T6>

The sixth Result<T> value.

Returns

Result<(T1, T2, T3, T4, T5, T6)>

A Result<T> containing a tuple of the six values if all succeeded; otherwise a ResultProblemCollection containing all validation problems.

Type Parameters

T1

The type of the first result value.

T2

The type of the second result value.

T3

The type of the third result value.

T4

The type of the fourth result value.

T5

The type of the fifth result value.

T6

The type of the sixth result value.

Concat<T1, T2, T3, T4, T5, T6>(Func<Result<T1>>, Func<Result<T2>>, Func<Result<T3>>, Func<Result<T4>>, Func<Result<T5>>, Func<Result<T6>>)

Invokes six functions that produce Result<T> values and concatenates them into a tuple by delegating to the non‑Func Concat<T1, T2, T3, T4, T5, T6>(Result<T1>, Result<T2>, Result<T3>, Result<T4>, Result<T5>, Result<T6>) overload.

public static Result<(T1, T2, T3, T4, T5, T6)> Concat<T1, T2, T3, T4, T5, T6>(Func<Result<T1>> a, Func<Result<T2>> b, Func<Result<T3>> c, Func<Result<T4>> d, Func<Result<T5>> e, Func<Result<T6>> f)

Parameters

a Func<Result<T1>>

A function that produces the first Result<T>.

b Func<Result<T2>>

A function that produces the second Result<T>.

c Func<Result<T3>>

A function that produces the third Result<T>.

d Func<Result<T4>>

A function that produces the fourth Result<T>.

e Func<Result<T5>>

A function that produces the fifth Result<T>.

f Func<Result<T6>>

A function that produces the sixth Result<T>.

Returns

Result<(T1, T2, T3, T4, T5, T6)>

A Result<T> containing a tuple of the six values if all succeeded; otherwise a ResultProblemCollection containing all aggregated problems.

Type Parameters

T1

The type of the first result value.

T2

The type of the second result value.

T3

The type of the third result value.

T4

The type of the fourth result value.

T5

The type of the fifth result value.

T6

The type of the sixth result value.

Failure(params IEnumerable<ResultProblem>)

Creates a result representing failure with the specified problems.

public static Result Failure(params IEnumerable<ResultProblem> problems)

Parameters

problems IEnumerable<ResultProblem>

The problems associated with the failure.

Returns

Result

A failure result.

Failure<T>(params IEnumerable<ResultProblem>)

Creates a result representing failure with the specified problems.

public static Result<T> Failure<T>(params IEnumerable<ResultProblem> problems)

Parameters

problems IEnumerable<ResultProblem>

The problems associated with the failure

Returns

Result<T>

A failure result.

Type Parameters

T

The success type of the failed result.

IfProblem(Action<ResultProblemCollection>)

Executes a sequence of functions that return a Result<T>.

public Result IfProblem(Action<ResultProblemCollection> action)

Parameters

action Action<ResultProblemCollection>

The function to execute.

Returns

Result

The result of the function.

Success()

Gets a result representing success.

public static Result Success()

Returns

Result

Success<T>(T)

Creates a result representing success with the specified value.

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

Parameters

value T

Returns

Result<T>

Type Parameters

T

ToString()

Returns the fully qualified type name of this instance.

public override string ToString()

Returns

string

The fully qualified type name.

TryPickProblems(out ResultProblemCollection?)

Attempts to retrieve the problems associated with the result.

public bool TryPickProblems(out ResultProblemCollection? problems)

Parameters

problems ResultProblemCollection

When this method returns true, contains the problems. Otherwise, null.

Returns

bool

true if problems exist; otherwise, false.

Try<TException>(Action, string?, params object[])

Attempts to execute the specified action and returns a Result. If an exception of type TException is thrown, it is captured as a problem in the result.

public static Result Try<TException>(Action action, string? message = null, params object[] args) where TException : Exception

Parameters

action Action

The action to execute.

message string

An optional message providing additional context if an exception is thrown. Supports composite formatting.

args object[]

Optional arguments for formatting the message.

Returns

Result

A successful result if no exception is thrown; otherwise, a failure result containing details of the caught exception.

Type Parameters

TException

The type of exception to catch.

Try<TValue, TException>(Func<TValue>, string?, params object[])

Attempts to execute the specified function and returns a Result<T>. If an exception of type TException is thrown, it is captured as a problem in the result.

public static Result<TValue> Try<TValue, TException>(Func<TValue> action, string? message = null, params object[] args) where TException : Exception

Parameters

action Func<TValue>

The function to execute.

message string

An optional message providing additional context if an exception is thrown. Supports composite formatting.

args object[]

Optional arguments for formatting the message.

Returns

Result<TValue>

A successful result containing the function's return value if no exception is thrown; otherwise, a failure result containing details of the caught exception.

Type Parameters

TValue

The type of value returned by the function.

TException

The type of exception to catch.

Operators

implicit operator Result(ResultProblem)

Converts the specified problem to a failure result.

public static implicit operator Result(ResultProblem problem)

Parameters

problem ResultProblem

The problem to convert.

Returns

Result

A failure result.

implicit operator Result(ResultProblemCollection)

Converts the specified problems to a failure result.

public static implicit operator Result(ResultProblemCollection problems)

Parameters

problems ResultProblemCollection

The problems to convert.

Returns

Result

A failure result.