Interface ISingleResultOpt<T>
Generic type for results of a single-element filter operation which represents a result count of zero, one, or more than one element.
Inherited Members
Namespace: Hgk.Zero.Options
Assembly: Hgk.Zero.Options.dll
Syntax
public interface ISingleResultOpt<out T> : IOpt<T>, IEnumerable<T>, ISingleResultOpt, IOpt, IEnumerable
Type Parameters
Name | Description |
---|---|
T | The type of value that may be contained in this option. |
Remarks
ISingleResultOpt<T> is the type returned by the single-element filter operations WhereSingle<TSource>(IEnumerable<TSource>) and WhereSingle<TSource>(IEnumerable<TSource>, Func<TSource, Boolean>). If such an operation finds zero elements or one element, a single-result option behaves the same as an ordinary IOpt<T>. However, if such an operation finds more than one element, it behaves differently:
- Resolving a single-result option as an ordinary option ( IOpt or IOpt<T>) or enumerable ( IEnumerable or IEnumerable<T>) will result in an InvalidOperationException. Operations that resolve immediately (such as a langword_csharp_foreach loop, ResolveOption<TResult>(Func<Boolean, T, TResult>), or Fix<TSource>(IOpt<TSource>)) will cause the exception to be thrown immediately, while deferred operations (such as Select<TSource, TResult>(IOpt<TSource>, Func<TSource, TResult>)) will cause the exception to be thrown when they are resolved themselves.
- Explicit operations such as ResolveSingleResultOption<TResult>(Func<Boolean, Boolean, T, TResult>) and methods from SingleResultOpt such as EmptyIfMoreThanOne<TSource>(ISingleResultOpt<TSource>) can be used to convert a single-result option to another kind of value without throwing an exception.
The following is information about the contract for this interface.
- The interface ISingleResultOpt must be implemented as specified.
- ResolveSingleResultOption<TResult>(Func<Boolean, Boolean, T, TResult>) must be implemented as specified.
-
ISingleResultOpt<T> implements IEnumerable and IEnumerable<T>. The contract of this interface requires that the enumerator returned
from GetEnumerator() and GetEnumerator()
behave as follows:
- If the operation produced no elements, the enumeration produces zero elements.
- If the operation produced one element, the enumeration produces that one element.
- If the operation produced more than one element, the enumeration throws InvalidOperationException instead of producing any elements. (The throwing of the exception should be deferred to the first MoveNext() rather than occurring immediately.)
Behavior is undefined if the enumerable produces more than one value.
Methods
| Improve this Doc View SourceResolveSingleResultOption<TResult>(Func<Boolean, Boolean, T, TResult>)
Resolves the contents of this single result option, producing a result using the specified result selector.
Declaration
TResult ResolveSingleResultOption<TResult>(Func<bool, bool, T, TResult> resultSelector)
Parameters
Type | Name | Description |
---|---|---|
Func<Boolean, Boolean, T, TResult> | resultSelector | A transform function that accepts an is-valid-option flag, a has-value flag, and a value. |
Returns
Type | Description |
---|---|
TResult | The result of calling resultSelector on the current resolved state of this single result option. |
Type Parameters
Name | Description |
---|---|
TResult | The return type of |
Remarks
The resolver function accepts three parameters: An is-valid-option flag, a has-value flag, and a value.
- If this single result option represents one result, the is-valid-option flag and has-value flag are true and the value parameter is the result value.
- If this single result option represents zero results, the is-valid-option flag is true, the has-value flag is false, and the value parameter is undefined.
- If this single result option represents more than one result (and is thus not a valid option), the is-valid-option flag is false and the remaining parameters are undefined.
If the has-value flag or the value parameter is undefined, the caller must not use their
values. To prevent accidental misuse, the implementation should supply false or langword_csharp_default( T
), respectively,
but this is not required.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|