public readonly struct Opt<T> : IEquatable<Opt<T>>
OptT | Option type of T: either None or Some value. Parameterless ctor returns None; better use SomeT(T) or NoneT to construct options by adding `using static OptRes.Ext`. |
IsNone |
Returns whether the option is None or not.
C#
|
AndT2(FuncOptT2) |
Combines two options: this and lazyOther as follows:
|
AndT2(OptT2) |
Combines two options: this and other as follows:
C#
|
AsNullable | Converts the option to nullable of T. |
Do |
Runs action(Unwrap()) only if IsSome; and returns itself back.
C#
|
DoIfNone |
Runs actionOnNone() only if IsNone; and returns itself back.
Counterpart of Do(ActionT) for the None variant.
C#
|
Equals(Object) |
Returns whether this option is equal to the other.
(Overrides ValueTypeEquals(Object)) |
Equals(OptT) | Returns true if both values are IsNone; or both IsSome and their unwrapped values are equal; false otherwise. |
FlatMapTOut(FuncT, OptTOut) |
Returns None when IsNone; map(val) when IsSome flattening the result.
Shorthand combining Map and Flatten calls.
C#
|
FlatMapTOut(FuncT, TaskOptTOut) |
(async version)
Returns None when IsNone; map(val) when IsSome flattening the result.
Shorthand combining Map and Flatten calls.
C#
|
GetHashCode |
Serves as the default hash function.
(Overrides ValueTypeGetHashCode) |
GetType | (Inherited from Object) |
MapTOut |
Returns None when IsNone; Some(map(Unwrap())) when IsSome.
C#
|
MapAsyncTOut |
(async version)
Returns None when IsNone; Some(map(Unwrap())) when IsSome.
C#
|
MatchTOut(FuncT, TOut, TOut) |
Maps into whenSome(Unwrap()) whenever IsSome; and into whenNone otherwise.
C#
|
MatchTOut(FuncT, TOut, FuncTOut) |
Maps into whenSome(Unwrap()) whenever IsSome; and into lazy whenNone() otherwise.
Similar to MatchTOut(FuncT, TOut, TOut) except that None variant is evaluated only when IsNone.
C#
|
MatchAsyncTOut |
(async version)
Maps into whenSome(Unwrap()) whenever IsSome; and into lazy whenNone() otherwise.
Similar to MatchTOut(FuncT, TOut, TOut) except that None variant is evaluated only when IsNone.
C#
|
MatchDo |
Executes whenSome(Unwrap()) if IsSome; whenNone() otherwise.
C#
|
Or(FuncOptT) |
(lazy version)
Combines two options: this and other as follows:
In other words, this is a flattened alternative to UnwrapOr(T). C#
|
Or(OptT) |
Combines two options: this and other as follows:
In other words, this is a flattened alternative to UnwrapOr(T). C#
|
Pure | Simply returns Some<T> function: val => Some(val). Useful for composing functions of Opt<T> type. |
SomeIf |
Returns back None if IsNone.
Otherwise, returns Some(value) if validationCriterion(value) holds; None if it does not hold.
Especially useful in fluent input validation.
C#
|
ThrowIfNone |
Returns the option back when IsSome; throws a NullReferenceException when IsNone.
Can be called without breaking the flow of chained operations.
C#
|
ThrowIfNone(String) |
Returns the option back when IsSome; throws a NullReferenceException when IsNone.
Appends the errorMessage to the exception if the message IsSome.
Can be called without breaking the flow of chained operations.
C#
|
ThrowIfNoneE(FuncE) |
Returns the option back when IsSome; throws a custom exception when IsNone.
Exception thrown when IsNone is created by the provided method getException.
Can be called without breaking the flow of chained operations.
C#
|
ToString |
Returns the text representation of the option.
(Overrides ValueTypeToString) |
Unwrap |
Returns the underlying value when IsSome; or throws when IsNone.
Must be called shyly, as it is not necessary to unwrap until the final result is achieved due to Map, FlatMap and TryMap methods.
C#
|
Unwrap(String) | Similar to Unwrap method except that the errorMessageIfNone is appended to the error message if IsNone. |
UnwrapOr(FuncT) |
Returns the underlying value when IsSome; or returns lazyFallbackValue() when IsNone.
This is a safe way to unwrap the optional, by explicitly handling the None variant.
Use the eager UnwrapOr(T) variant if the fallback value is cheap or readily available.
C#
|
UnwrapOr(T) |
Returns the underlying value when IsSome; or returns the fallbackValue when IsNone.
This is a safe way to unwrap the optional, by explicitly handling the None variant.
Use the lazy UnwrapOr(FuncT) variant if the computation of the fallback value is expensive.
C#
|
UnwrapOrAsync |
(async version)
Returns the underlying value when IsSome; or returns lazyFallbackValue() when IsNone.
This is a safe way to unwrap the optional, by explicitly handling the None variant.
Use the eager UnwrapOr(T) variant if the fallback value is cheap or readily available.
C#
|
Equality(OptT, OptT) |
Returns true if both values are IsSome and their unwrapped values are equal; false otherwise.
C#
|
Inequality(OptT, OptT) |
Returns true if either value is IsNone or their unwrapped values are not equal; false otherwise.
C#
|
IsSome |
Returns whether the option has Some value or not.
C#
|