Class SingleResultOpt
Facilities to manipulate single result options.
Inherited Members
Namespace: Hgk.Zero.Options
Assembly: Hgk.Zero.Options.dll
Syntax
public static class SingleResultOpt
Methods
| Improve this Doc View SourceDefaultIfMoreThanOne<TSource>(ISingleResultOpt<TSource>)
Converts a single result option to another option, substituting a full option containing the default value of the contained type if this option represents more than one result.
Declaration
public static IOpt<TSource> DefaultIfMoreThanOne<TSource>(this ISingleResultOpt<TSource> source)
Parameters
Type | Name | Description |
---|---|---|
ISingleResultOpt<TSource> | source | A source single result option. |
Returns
Type | Description |
---|---|
IOpt<TSource> | An option equivalent to |
Type Parameters
Name | Description |
---|---|
TSource | The element type of |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
DefaultIfMoreThanOne<TSource>(ISingleResultOpt<TSource>, TSource)
Converts a single result option to another option, substituting a full option containing the specified default value if this option represents more than one result.
Declaration
public static IOpt<TSource> DefaultIfMoreThanOne<TSource>(this ISingleResultOpt<TSource> source, TSource defaultValue)
Parameters
Type | Name | Description |
---|---|---|
ISingleResultOpt<TSource> | source | A source single result option. |
TSource | defaultValue | The value to be contained by the returned option if |
Returns
Type | Description |
---|---|
IOpt<TSource> | An option equivalent to |
Type Parameters
Name | Description |
---|---|
TSource | The element type of |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
EmptyIfMoreThanOne<TSource>(ISingleResultOpt<TSource>)
Converts a single result option to another option, substituting an empty option if this option represents more than one result.
Declaration
public static IOpt<TSource> EmptyIfMoreThanOne<TSource>(this ISingleResultOpt<TSource> source)
Parameters
Type | Name | Description |
---|---|---|
ISingleResultOpt<TSource> | source | A source single result option. |
Returns
Type | Description |
---|---|
IOpt<TSource> | An option equivalent to |
Type Parameters
Name | Description |
---|---|
TSource | The element type of |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ForceSingleResultOpt(ISingleResultOpt)
Immediately computes the result of any deferred computation represented by a single result option and returns a new single result option representing the final result.
Declaration
public static ISingleResultOpt ForceSingleResultOpt(this ISingleResultOpt source)
Parameters
Type | Name | Description |
---|---|---|
ISingleResultOpt | source | A source single result option. |
Returns
Type | Description |
---|---|
ISingleResultOpt | A single result option representing the final result of any deferred computation
represented by |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ForceSingleResultOpt<TSource>(ISingleResultOpt<TSource>)
Immediately computes the result of any deferred computation represented by a single result option and returns a new single result option representing the final result.
Declaration
public static ISingleResultOpt<TSource> ForceSingleResultOpt<TSource>(this ISingleResultOpt<TSource> source)
Parameters
Type | Name | Description |
---|---|---|
ISingleResultOpt<TSource> | source | A source single result option. |
Returns
Type | Description |
---|---|
ISingleResultOpt<TSource> | A single result option representing the final result of any deferred computation
represented by |
Type Parameters
Name | Description |
---|---|
TSource | The element type of |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
Match<TSource, TResult>(ISingleResultOpt<TSource>, Func<TResult>, Func<TSource, TResult>, Func<TResult>)
Converts a single result option to another value based on its contents.
Declaration
public static TResult Match<TSource, TResult>(this ISingleResultOpt<TSource> source, Func<TResult> ifZero = null, Func<TSource, TResult> ifOne = null, Func<TResult> ifMoreThanOne = null)
Parameters
Type | Name | Description |
---|---|---|
ISingleResultOpt<TSource> | source | A source single result option. |
Func<TResult> | ifZero | A function to produce the result if |
Func<TSource, TResult> | ifOne | A function to produce the result if |
Func<TResult> | ifMoreThanOne | A function to produce the result if |
Returns
Type | Description |
---|---|
TResult | The result of calling |
Type Parameters
Name | Description |
---|---|
TSource | The element type of |
TResult | The type of the result of this conversion. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
InvalidOperationException |
|
MatchOpt<TSource, TResult>(ISingleResultOpt<TSource>, Func<Opt<TResult>>, Func<TSource, Opt<TResult>>, Func<Opt<TResult>>)
Converts a single result option to another option based on its contents.
Declaration
public static IOpt<TResult> MatchOpt<TSource, TResult>(this ISingleResultOpt<TSource> source, Func<Opt<TResult>> ifZero = null, Func<TSource, Opt<TResult>> ifOne = null, Func<Opt<TResult>> ifMoreThanOne = null)
Parameters
Type | Name | Description |
---|---|---|
ISingleResultOpt<TSource> | source | A source single result option. |
Func<Opt<TResult>> | ifZero | A function to produce the result if |
Func<TSource, Opt<TResult>> | ifOne | A function to produce the result if |
Func<Opt<TResult>> | ifMoreThanOne | A function to produce the result if |
Returns
Type | Description |
---|---|
IOpt<TResult> | An option equivalent to the result of calling |
Type Parameters
Name | Description |
---|---|
TSource | The element type of |
TResult | The element type of the result option for this conversion. |
Remarks
This method is implemented using deferred execution; the query represented by this method is not performed until the contents of the returned option are resolved, such as by enumeration.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
InvalidOperationException |
|
ReplaceIfMoreThanOne<TSource>(ISingleResultOpt<TSource>, IOpt<TSource>)
Converts a single result option to another option, substituting a specified option if this option represents more than one result.
Declaration
public static IOpt<TSource> ReplaceIfMoreThanOne<TSource>(this ISingleResultOpt<TSource> source, IOpt<TSource> replacement)
Parameters
Type | Name | Description |
---|---|---|
ISingleResultOpt<TSource> | source | A source single result option. |
IOpt<TSource> | replacement | An option to produce the result if |
Returns
Type | Description |
---|---|
IOpt<TSource> | An option equivalent to |
Type Parameters
Name | Description |
---|---|
TSource | The element type of |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ReplaceIfMoreThanOne<TSource>(ISingleResultOpt<TSource>, Func<IOpt<TSource>>)
Converts a single result option to another option, substituting the result of a callback if this option represents more than one result.
Declaration
public static IOpt<TSource> ReplaceIfMoreThanOne<TSource>(this ISingleResultOpt<TSource> source, Func<IOpt<TSource>> replacementFactory)
Parameters
Type | Name | Description |
---|---|---|
ISingleResultOpt<TSource> | source | A source single result option. |
Func<IOpt<TSource>> | replacementFactory | A function to produce the result if |
Returns
Type | Description |
---|---|
IOpt<TSource> | An option equivalent to |
Type Parameters
Name | Description |
---|---|
TSource | The element type of |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|