Table of Contents

Method ValueOrThrow

Namespace
SodaFlow.Functional
Assembly
SodaFlow.Functional.dll

ValueOrThrow<T>(Maybe<T>, Func<Exception>)

Returns the contained value if there is one, and throws the exception produced by the given function otherwise.

public static T ValueOrThrow<T>(this Maybe<T> a, Func<Exception> onNone)

Parameters

a Maybe<T>

The value to read.

onNone Func<Exception>

Run to give the exception to throw when there is no value.

Returns

T

The contained value.

Type Parameters

T

The type of the value.

Remarks

The deliberate exit, for the boundary where the absence of a value really is a failure - a necessary configuration value, for example. It makes the caller answer for the empty condition, by making them say what the failure is.

Exceptions

Exception

Whatever onNone produced, when there is no contained value.