Interface IOpt<T>
Generic type for options.
Inherited Members
Namespace: Hgk.Zero.Options
Assembly: Hgk.Zero.Options.dll
Syntax
public interface IOpt<out T> : IOpt, IEnumerable<T>, IEnumerable
Type Parameters
Name | Description |
---|---|
T | The type of value that may be contained in this option. |
Remarks
IOpt<T> implements IEnumerable and IEnumerable<T>. The contract of this interface requires that the enumerators returned from GetEnumerator() and GetEnumerator() produce either zero values, if the option is empty, or one value, if the option is full. Behavior is undefined if the enumerable produces more than one value.
In general, this interface should not be directly implemented in an application. Instead:
- If the contained value is known immediately, use the fixed option type Opt<T>. An instance can be created using static methods of Opt including Create<T>(T), Full<T>(T), and Empty<T>().
- If the contained value is not yet determined and should be deferred, use Defer<T>(Func<Opt<T>>) to create a deferred option based on a function that returns a fixed option.
- If the contained value is the first element, last element, an element at a particular index, or the only element of an IEnumerable<T>, use WhereFirst<TSource>(IEnumerable<TSource>), WhereLast<TSource>(IEnumerable<TSource>), WhereElementAt<TSource>(IEnumerable<TSource>, Int32), or WhereSingle<TSource>(IEnumerable<TSource>), respectively, to obtain a deferred option containing the indicated element.
Methods
| Improve this Doc View SourceResolveOption<TResult>(Func<Boolean, T, TResult>)
Resolves the contents of this option, producing a result using the specified result selector function.
Declaration
TResult ResolveOption<TResult>(Func<bool, T, TResult> resultSelector)
Parameters
Type | Name | Description |
---|---|---|
Func<Boolean, T, TResult> | resultSelector | A transform function that accepts a has-value flag and a value. |
Returns
Type | Description |
---|---|
TResult | The result of calling |
Type Parameters
Name | Description |
---|---|
TResult | The return type of |
Remarks
The resolver function accepts two parameters: A has-value flag and a value. (These values roughly correspond to Any<TSource>(IOpt<TSource>) and SingleOrDefault<TSource>(IOpt<TSource>), respectively.)
- If this option contains a value, the has-value flag is true and the value parameter is the contained value.
-
If this option is empty, the has-value flag is false and the value
parameter is undefined. (The caller must not use the value of the value parameter. In
order to prevent accidental misbehavior, the implementation should supply langword_csharp_default(
T
), but this is not required.)
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|