Show / Hide Table of Contents

Class SingleResultOpt

Facilities to manipulate single result options.

Inheritance
Object
SingleResultOpt
Inherited Members
Object.Equals(Object)
Object.Equals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Object.ToString()
Namespace: Hgk.Zero.Options
Assembly: Hgk.Zero.Options.dll
Syntax
public static class SingleResultOpt

Methods

| Improve this Doc View Source

DefaultIfMoreThanOne<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 source, if it represents a result of zero or one element; otherwise, an option containing the default value of TSource.

Type Parameters
Name Description
TSource

The element type of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

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 source represents more than one result.

Returns
Type Description
IOpt<TSource>

An option equivalent to source, if it represents a result of zero or one element; otherwise, an option containing defaultValue.

Type Parameters
Name Description
TSource

The element type of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

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 source, if it represents a result of zero or one element; otherwise, an empty option.

Type Parameters
Name Description
TSource

The element type of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

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 source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

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 source.

Type Parameters
Name Description
TSource

The element type of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

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 source represents a result of zero elements.

Func<TSource, TResult> ifOne

A function to produce the result if source represents a result of one element, which accepts that element as a parameter.

Func<TResult> ifMoreThanOne

A function to produce the result if source represents a result of more than one element.

Returns
Type Description
TResult

The result of calling ifZero, ifOne, or ifMoreThanOne if source represents a result of zero, one, or more than one element, respectively.

Type Parameters
Name Description
TSource

The element type of source.

TResult

The type of the result of this conversion.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

ifZero is null and source represents a result of zero elements, or ifOne is null and source represents a result of one element, or ifMoreThanOne is null and source represents a result of more than one element.

| Improve this Doc View Source

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 source represents a result of zero elements.

Func<TSource, Opt<TResult>> ifOne

A function to produce the result if source represents a result of one element, which accepts that element as a parameter.

Func<Opt<TResult>> ifMoreThanOne

A function to produce the result if source represents a result of more than one element.

Returns
Type Description
IOpt<TResult>

An option equivalent to the result of calling ifZero, ifOne, or ifMoreThanOne if source represents a result of zero, one, or more than one element, respectively.

Type Parameters
Name Description
TSource

The element type of source.

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

source is null.

InvalidOperationException

ifZero is null and source represents a result of zero elements, or ifOne is null and source represents a result of one element, or ifMoreThanOne is null and source represents a result of more than one element.

| Improve this Doc View Source

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 source represents a result of more than one element.

Returns
Type Description
IOpt<TSource>

An option equivalent to source, if it represents a result of zero or one element; otherwise, an option equivalent to replacement.

Type Parameters
Name Description
TSource

The element type of source.

Exceptions
Type Condition
ArgumentNullException

source or replacement is null.

| Improve this Doc View Source

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 source represents a result of more than one element.

Returns
Type Description
IOpt<TSource>

An option equivalent to source, if it represents a result of zero or one element; otherwise, an option equivalent to the result of calling replacementFactory.

Type Parameters
Name Description
TSource

The element type of source.

Exceptions
Type Condition
ArgumentNullException

source or replacementFactory is null.

See Also

ISingleResultOpt
ISingleResultOpt<T>
WhereSingle<TSource>(IEnumerable<TSource>)
WhereSingle<TSource>(IEnumerable<TSource>, Func<TSource, Boolean>)
  • Improve this Doc
  • View Source
Back to top Copyright © 2018-2019 Peter S. May
Generated by DocFX