Show / Hide Table of Contents

Class LinqToOpt

LINQ facilities for options.

Inheritance
Object
LinqToOpt
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.Linq
Assembly: Hgk.Zero.Options.dll
Syntax
public static class LinqToOpt
Remarks

This class contains a large number of LINQ-compatible methods. While all options are also enumerables, and can therefore be used with methods provided by Enumerable, most of the operators are specialized here for options in order to optimize the algorithms for use with zero- or one-element collections (such as Distinct<TSource>(IOpt<TSource>)), and also to return options from operations guaranteed to return at most one element when performed on an option (such as Zip<TFirst, TSecond, TResult>(IOpt<TFirst>, IEnumerable<TSecond>, Func<TFirst, TSecond, TResult>)). In general, the result of applying any LINQ operation in this class to an option is defined to be sequence-equal to the result of applying the same operation from Enumerable to the same option.

Similarly to the methods in Enumerable, most option-returning methods in this class are implemented using deferred execution; that is, the query represented by the method is not actually executed until the contents of the result are resolved directly, for example, by enumeration, using foreach, or calling a method such as ToFixed<TSource>(IOpt<TSource>) or Match<TSource, TResult>(IOpt<TSource>, Func<TResult>, Func<TSource, TResult>).

Some methods instead use or return Opt<T>, which is a type for fixed, immutable options. The contents of these are immediate and not deferred.

Methods

| Improve this Doc View Source

Aggregate<TSource>(IOpt<TSource>, Func<TSource, TSource, TSource>)

Applies an accumulator function over the elements of an option.

Declaration
public static TSource Aggregate<TSource>(this IOpt<TSource> source, Func<TSource, TSource, TSource> func)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, TSource, TSource> func

An accumulator function to be applied to an element of source.

Returns
Type Description
TSource

The final accumulator value, which is the single element of source.

Type Parameters
Name Description
TSource

The type of the elements of source.

Remarks

Since an option can only ever have zero elements or one element, func is never called (but must still be supplied).

Exceptions
Type Condition
ArgumentNullException

source or func is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Aggregate<TSource, TAccumulate>(IOpt<TSource>, TAccumulate, Func<TAccumulate, TSource, TAccumulate>)

Applies an accumulator function over the elements of an option, using the specified seed value.

Declaration
public static TAccumulate Aggregate<TSource, TAccumulate>(this IOpt<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> func)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

TAccumulate seed

The initial value for the accumulator.

Func<TAccumulate, TSource, TAccumulate> func

An accumulator function to be applied to the accumulator and an element of source.

Returns
Type Description
TAccumulate

The final accumulator value, which is either seed, if source is empty, or the result of applying func to seed and the single element of source, otherwise.

Type Parameters
Name Description
TSource

The type of the elements of source.

TAccumulate

The type of the accumulator value.

Exceptions
Type Condition
ArgumentNullException

source or func is null.

| Improve this Doc View Source

Aggregate<TSource, TAccumulate, TResult>(IOpt<TSource>, TAccumulate, Func<TAccumulate, TSource, TAccumulate>, Func<TAccumulate, TResult>)

Applies an accumulator function over the elements of an option, using the specified seed value, and transforming the final result with the specified result selector.

Declaration
public static TResult Aggregate<TSource, TAccumulate, TResult>(this IOpt<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> func, Func<TAccumulate, TResult> resultSelector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

TAccumulate seed

The initial value for the accumulator.

Func<TAccumulate, TSource, TAccumulate> func

An accumulator function to be applied to the accumulator and an element of source.

Func<TAccumulate, TResult> resultSelector

A function to transform the accumulator value into the result.

Returns
Type Description
TResult

The result of applying resultSelector to the final accumulator value, which is either seed, if source is empty, or the result of applying func to seed and the single element of source, otherwise.

Type Parameters
Name Description
TSource

The type of the elements of source.

TAccumulate

The type of the accumulator value.

TResult

The type of the result.

Exceptions
Type Condition
ArgumentNullException

source, func, or resultSelector is null.

| Improve this Doc View Source

All<TSource>(IOpt<TSource>, Func<TSource, Boolean>)

Returns whether all elements of an option satisfy a predicate.

Declaration
public static bool All<TSource>(this IOpt<TSource> source, Func<TSource, bool> predicate)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Boolean> predicate

A function to test each element for a condition.

Returns
Type Description
Boolean

true, if source is empty or contains an element that satisfies predicate; otherwise, false.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source or predicate is null.

| Improve this Doc View Source

Any<TSource>(IOpt<TSource>)

Returns whether an option contains any elements.

Declaration
public static bool Any<TSource>(this IOpt<TSource> source)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Returns
Type Description
Boolean

true if source contains an element; otherwise, false.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Any<TSource>(IOpt<TSource>, Func<TSource, Boolean>)

Returns whether any element of an option satisfies a predicate.

Declaration
public static bool Any<TSource>(this IOpt<TSource> source, Func<TSource, bool> predicate)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Boolean> predicate

A function to test each element for a condition.

Returns
Type Description
Boolean

true, if source contains an element that satisfies predicate; otherwise, false.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source or predicate is null.

| Improve this Doc View Source

AsIOpt<TSource>(IOpt<TSource>)

Returns this option typed as IOpt<T>.

Declaration
public static IOpt<TSource> AsIOpt<TSource>(this IOpt<TSource> source)
Parameters
Type Name Description
IOpt<TSource> source

An option to type as IOpt<T>.

Returns
Type Description
IOpt<TSource>

source, typed as IOpt<T>.

Type Parameters
Name Description
TSource

The element type of source.

| Improve this Doc View Source

Average(IOpt<Decimal>)

Computes the average of the contents of an option.

Declaration
public static decimal Average(this IOpt<decimal> source)
Parameters
Type Name Description
IOpt<Decimal> source

A source option.

Returns
Type Description
Decimal

The value of the only element of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Average(IOpt<Double>)

Computes the average of the contents of an option.

Declaration
public static double Average(this IOpt<double> source)
Parameters
Type Name Description
IOpt<Double> source

A source option.

Returns
Type Description
Double

The value of the only element of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Average(IOpt<Int32>)

Computes the average of the contents of an option.

Declaration
public static double Average(this IOpt<int> source)
Parameters
Type Name Description
IOpt<Int32> source

A source option.

Returns
Type Description
Double

The value of the only element of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Average(IOpt<Int64>)

Computes the average of the contents of an option.

Declaration
public static double Average(this IOpt<long> source)
Parameters
Type Name Description
IOpt<Int64> source

A source option.

Returns
Type Description
Double

The value of the only element of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Average(IOpt<Nullable<Decimal>>)

Computes the average of the non-null contents of an option.

Declaration
public static decimal? Average(this IOpt<decimal? > source)
Parameters
Type Name Description
IOpt<Nullable<Decimal>> source

A source option.

Returns
Type Description
Nullable<Decimal>

The value of the only element of source, if source contains a value; otherwise, null.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Average(IOpt<Nullable<Double>>)

Computes the average of the non-null contents of an option.

Declaration
public static double? Average(this IOpt<double? > source)
Parameters
Type Name Description
IOpt<Nullable<Double>> source

A source option.

Returns
Type Description
Nullable<Double>

The value of the only element of source, if source contains a value; otherwise, null.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Average(IOpt<Nullable<Int32>>)

Computes the average of the non-null contents of an option.

Declaration
public static double? Average(this IOpt<int? > source)
Parameters
Type Name Description
IOpt<Nullable<Int32>> source

A source option.

Returns
Type Description
Nullable<Double>

The value of the only element of source, if source contains a value; otherwise, null.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Average(IOpt<Nullable<Int64>>)

Computes the average of the non-null contents of an option.

Declaration
public static double? Average(this IOpt<long? > source)
Parameters
Type Name Description
IOpt<Nullable<Int64>> source

A source option.

Returns
Type Description
Nullable<Double>

The value of the only element of source, if source contains a value; otherwise, null.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Average(IOpt<Nullable<Single>>)

Computes the average of the non-null contents of an option.

Declaration
public static float? Average(this IOpt<float? > source)
Parameters
Type Name Description
IOpt<Nullable<Single>> source

A source option.

Returns
Type Description
Nullable<Single>

The value of the only element of source, if source contains a value; otherwise, null.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Average(IOpt<Single>)

Computes the average of the contents of an option.

Declaration
public static float Average(this IOpt<float> source)
Parameters
Type Name Description
IOpt<Single> source

A source option.

Returns
Type Description
Single

The value of the only element of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Average<TSource>(IOpt<TSource>, Func<TSource, Decimal>)

Computes the average of a projection of the contents of an option.

Declaration
public static decimal Average<TSource>(this IOpt<TSource> source, Func<TSource, decimal> selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Decimal> selector

A transform function applied to each element of source.

Returns
Type Description
Decimal

The value of the result of applying selector to the only element of source.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Average<TSource>(IOpt<TSource>, Func<TSource, Double>)

Computes the average of a projection of the contents of an option.

Declaration
public static double Average<TSource>(this IOpt<TSource> source, Func<TSource, double> selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Double> selector

A transform function applied to each element of source.

Returns
Type Description
Double

The value of the result of applying selector to the only element of source.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Average<TSource>(IOpt<TSource>, Func<TSource, Int32>)

Computes the average of a projection of the contents of an option.

Declaration
public static double Average<TSource>(this IOpt<TSource> source, Func<TSource, int> selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Int32> selector

A transform function applied to each element of source.

Returns
Type Description
Double

The value of the result of applying selector to the only element of source.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Average<TSource>(IOpt<TSource>, Func<TSource, Int64>)

Computes the average of a projection of the contents of an option.

Declaration
public static double Average<TSource>(this IOpt<TSource> source, Func<TSource, long> selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Int64> selector

A transform function applied to each element of source.

Returns
Type Description
Double

The value of the result of applying selector to the only element of source.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Average<TSource>(IOpt<TSource>, Func<TSource, Nullable<Decimal>>)

Computes the average of the non-null elements of a projection of the contents of an option.

Declaration
public static decimal? Average<TSource>(this IOpt<TSource> source, Func<TSource, decimal? > selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Nullable<Decimal>> selector

A transform function applied to each element of source.

Returns
Type Description
Nullable<Decimal>

The value of the result of applying selector to the only element of source, if source contains a value; otherwise, null.

Type Parameters
Name Description
TSource

The type of the elements of source.

| Improve this Doc View Source

Average<TSource>(IOpt<TSource>, Func<TSource, Nullable<Double>>)

Computes the average of the non-null elements of a projection of the contents of an option.

Declaration
public static double? Average<TSource>(this IOpt<TSource> source, Func<TSource, double? > selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Nullable<Double>> selector

A transform function applied to each element of source.

Returns
Type Description
Nullable<Double>

The value of the result of applying selector to the only element of source, if source contains a value; otherwise, null.

Type Parameters
Name Description
TSource

The type of the elements of source.

| Improve this Doc View Source

Average<TSource>(IOpt<TSource>, Func<TSource, Nullable<Int32>>)

Computes the average of the non-null elements of a projection of the contents of an option.

Declaration
public static double? Average<TSource>(this IOpt<TSource> source, Func<TSource, int? > selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Nullable<Int32>> selector

A transform function applied to each element of source.

Returns
Type Description
Nullable<Double>

The value of the result of applying selector to the only element of source, if source contains a value; otherwise, null.

Type Parameters
Name Description
TSource

The type of the elements of source.

| Improve this Doc View Source

Average<TSource>(IOpt<TSource>, Func<TSource, Nullable<Int64>>)

Computes the average of the non-null elements of a projection of the contents of an option.

Declaration
public static double? Average<TSource>(this IOpt<TSource> source, Func<TSource, long? > selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Nullable<Int64>> selector

A transform function applied to each element of source.

Returns
Type Description
Nullable<Double>

The value of the result of applying selector to the only element of source, if source contains a value; otherwise, null.

Type Parameters
Name Description
TSource

The type of the elements of source.

| Improve this Doc View Source

Average<TSource>(IOpt<TSource>, Func<TSource, Nullable<Single>>)

Computes the average of the non-null elements of a projection of the contents of an option.

Declaration
public static float? Average<TSource>(this IOpt<TSource> source, Func<TSource, float? > selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Nullable<Single>> selector

A transform function applied to each element of source.

Returns
Type Description
Nullable<Single>

The value of the result of applying selector to the only element of source, if source contains a value; otherwise, null.

Type Parameters
Name Description
TSource

The type of the elements of source.

| Improve this Doc View Source

Average<TSource>(IOpt<TSource>, Func<TSource, Single>)

Computes the average of a projection of the contents of an option.

Declaration
public static float Average<TSource>(this IOpt<TSource> source, Func<TSource, float> selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Single> selector

A transform function applied to each element of source.

Returns
Type Description
Single

The value of the result of applying selector to the only element of source.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Cast<TResult>(IOpt)

Casts the elements of an option to the specified type.

Declaration
public static IOpt<TResult> Cast<TResult>(this IOpt source)
Parameters
Type Name Description
IOpt source

A source option.

Returns
Type Description
IOpt<TResult>

An option having the same contents as source, cast to TResult.

Type Parameters
Name Description
TResult

The type to which to cast the elements of source.

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.

If source is already an IOpt<T> with TResult as its element type, it is returned unchanged.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidCastException

source is not empty and its element cannot be cast to TResult. (Deferred.)

| Improve this Doc View Source

Contains<TSource>(IOpt<TSource>, TSource)

Determines whether an option contains an element that equals the specified value.

Declaration
public static bool Contains<TSource>(this IOpt<TSource> source, TSource value)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

TSource value

A value to find in source.

Returns
Type Description
Boolean

true, if source contains an element that equals value; otherwise, false.

Type Parameters
Name Description
TSource

The type of the elements of source.

Remarks

The comparison, if any, is performed using Default for TSource.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Contains<TSource>(IOpt<TSource>, TSource, IEqualityComparer<TSource>)

Determines whether an option contains an element that equals the specified value, according to the specified comparer.

Declaration
public static bool Contains<TSource>(this IOpt<TSource> source, TSource value, IEqualityComparer<TSource> comparer)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

TSource value

A value to find in source.

IEqualityComparer<TSource> comparer

A comparer to determine whether values are equal. (If null, Default is used.)

Returns
Type Description
Boolean

true, if source contains an element that equals value; otherwise, false.

Type Parameters
Name Description
TSource

The type of the elements of source.

Remarks

The comparison, if any, is performed using comparer. If comparer is null, Default for TSource is used instead.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Count<TSource>(IOpt<TSource>)

Returns the number of elements in an option.

Declaration
public static int Count<TSource>(this IOpt<TSource> source)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Returns
Type Description
Int32

1 if source contains an element; otherwise, 0.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Count<TSource>(IOpt<TSource>, Func<TSource, Boolean>)

Returns the number of elements of an option that satisfy a predicate.

Declaration
public static int Count<TSource>(this IOpt<TSource> source, Func<TSource, bool> predicate)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Boolean> predicate

A function to test each element for a condition.

Returns
Type Description
Int32

1, if source contains an element that satisfies predicate; otherwise, 0.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source or predicate is null.

| Improve this Doc View Source

DefaultIfEmpty<TSource>(IOpt<TSource>)

Returns a full option containing either the same contents as a specified option, if it is full, or the default value for the type, if it is empty.

Declaration
public static IOpt<TSource> DefaultIfEmpty<TSource>(this IOpt<TSource> source)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Returns
Type Description
IOpt<TSource>

An option that is equivalent to source, if source is full; otherwise, a full option containing the langword_csharp_default value for the type.

Type Parameters
Name Description
TSource

The type of the elements of source.

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.

| Improve this Doc View Source

DefaultIfEmpty<TSource>(IOpt<TSource>, TSource)

Returns a full option containing either the same contents as a specified option, if it is full, or a specified default value, if it is empty.

Declaration
public static IOpt<TSource> DefaultIfEmpty<TSource>(this IOpt<TSource> source, TSource defaultValue)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

TSource defaultValue

A default value for the result to contain if source is empty.

Returns
Type Description
IOpt<TSource>

An option that is equivalent to source, if source is full; otherwise, a full option containing defaultValue.

Type Parameters
Name Description
TSource

The type of the elements of source.

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.

| Improve this Doc View Source

Distinct<TSource>(IOpt<TSource>)

Returns distinct elements from an option.

Declaration
public static IOpt<TSource> Distinct<TSource>(this IOpt<TSource> source)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Returns
Type Description
IOpt<TSource>

source.

Type Parameters
Name Description
TSource

The type of the elements of source.

Remarks

Since an option, by virtue of being a zero- or one-element sequence, never contains duplicate elements, this method returns source unmodified (after ensuring that it is not null).

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Distinct<TSource>(IOpt<TSource>, IEqualityComparer<TSource>)

Returns distinct elements from an option.

Declaration
public static IOpt<TSource> Distinct<TSource>(this IOpt<TSource> source, IEqualityComparer<TSource> comparer)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

IEqualityComparer<TSource> comparer

A comparer used to test values for equality. (This parameter is ignored.)

Returns
Type Description
IOpt<TSource>

source.

Type Parameters
Name Description
TSource

The type of the elements of source.

Remarks

Since an option, by virtue of being a zero- or one-element sequence, never contains duplicate elements, this method returns source unmodified (after ensuring that it is not null).

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

ElementAt<TSource>(IOpt<TSource>, Int32)

Returns the element at a specified index in an option.

Declaration
public static TSource ElementAt<TSource>(this IOpt<TSource> source, int index)
Parameters
Type Name Description
IOpt<TSource> source

An option to return an element from.

Int32 index

The index of the element to retrieve.

Returns
Type Description
TSource

The element at the specified position in source.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

ArgumentOutOfRangeException

source is empty or index is nonzero.

| Improve this Doc View Source

ElementAtOrDefault<TSource>(IOpt<TSource>, Int32)

Returns the element at a specified index in an option or the type's default value if the index is out of range.

Declaration
public static TSource ElementAtOrDefault<TSource>(this IOpt<TSource> source, int index)
Parameters
Type Name Description
IOpt<TSource> source

An option to return an element from.

Int32 index

The index of the element to retrieve.

Returns
Type Description
TSource

The default value of TSource if the index is outside the bounds of source; otherwise, the element at the specified position in source.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

ElementAtOrDefault<TSource>(IOpt<TSource>, Int32, TSource)

Returns the element at a specified index in an option or a default value if the index is out of range.

Declaration
public static TSource ElementAtOrDefault<TSource>(this IOpt<TSource> source, int index, TSource defaultValue)
Parameters
Type Name Description
IOpt<TSource> source

An option to return an element from.

Int32 index

The index of the element to retrieve.

TSource defaultValue

A default value to return if index is out of bounds.

Returns
Type Description
TSource

defaultValue if the index is outside the bounds of source; otherwise, the element at the specified position in source.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Except<TSource>(IOpt<TSource>, IEnumerable<TSource>)

Finds the elements of an option that do not appear in a sequence.

Declaration
public static IOpt<TSource> Except<TSource>(this IOpt<TSource> first, IEnumerable<TSource> second)
Parameters
Type Name Description
IOpt<TSource> first

An option whose elements are to be subtracted from.

IEnumerable<TSource> second

A sequence of elements to subtract from first.

Returns
Type Description
IOpt<TSource>

An option equivalent to first, if the element of first does not appear in second; otherwise, an empty option.

Type Parameters
Name Description
TSource

The type of the elements of first and second.

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

first or second is null.

| Improve this Doc View Source

Except<TSource>(IOpt<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>)

Finds the elements of an option that do not appear in a sequence, using the specified comparer to determine equality.

Declaration
public static IOpt<TSource> Except<TSource>(this IOpt<TSource> first, IEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
Parameters
Type Name Description
IOpt<TSource> first

An option whose elements are to be subtracted from.

IEnumerable<TSource> second

A sequence of elements to subtract from first.

IEqualityComparer<TSource> comparer

A comparer to determine whether elements are equal. (If null, Default is used.)

Returns
Type Description
IOpt<TSource>

An option equivalent to first, if the element of first does not appear in second; otherwise, an empty option.

Type Parameters
Name Description
TSource

The type of the elements of first and second.

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

first or second is null.

| Improve this Doc View Source

First<TSource>(IOpt<TSource>)

Returns the first element of an option.

Declaration
public static TSource First<TSource>(this IOpt<TSource> source)
Parameters
Type Name Description
IOpt<TSource> source

An option to return an element from.

Returns
Type Description
TSource

The first element of source.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

First<TSource>(IOpt<TSource>, Func<TSource, Boolean>)

Returns the first element of an option that satisfies a condition.

Declaration
public static TSource First<TSource>(this IOpt<TSource> source, Func<TSource, bool> predicate)
Parameters
Type Name Description
IOpt<TSource> source

An option to return an element from.

Func<TSource, Boolean> predicate

A function to test each element for a condition.

Returns
Type Description
TSource

The first element of source that satisfies predicate.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source does not contain any element that satisfies predicate.

| Improve this Doc View Source

FirstOrDefault<TSource>(IOpt<TSource>)

Returns the first element of an option, or the default value for the type if the option is empty.

Declaration
public static TSource FirstOrDefault<TSource>(this IOpt<TSource> source)
Parameters
Type Name Description
IOpt<TSource> source

An option to return an element from.

Returns
Type Description
TSource

The first element of source, or the default value for TSource if source is empty.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

FirstOrDefault<TSource>(IOpt<TSource>, TSource)

Returns the first element of an option, or a specified default value if the option is empty.

Declaration
public static TSource FirstOrDefault<TSource>(this IOpt<TSource> source, TSource defaultValue)
Parameters
Type Name Description
IOpt<TSource> source

An option to return an element from.

TSource defaultValue

A default value to return if source contains no elements.

Returns
Type Description
TSource

The first element of source, or defaultValue if source is empty.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

FirstOrDefault<TSource>(IOpt<TSource>, Func<TSource, Boolean>)

Returns the first element of an option that satisfies a condition, or the default value for the type if no such element is found.

Declaration
public static TSource FirstOrDefault<TSource>(this IOpt<TSource> source, Func<TSource, bool> predicate)
Parameters
Type Name Description
IOpt<TSource> source

An option to return an element from.

Func<TSource, Boolean> predicate

A function to test each element for a condition.

Returns
Type Description
TSource

The first element of source that satisfies predicate, or the default value for TSource if no such element is found.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source or predicate is null.

| Improve this Doc View Source

FirstOrDefault<TSource>(IOpt<TSource>, Func<TSource, Boolean>, TSource)

Returns the first element of an option that satisfies a condition, or a specified default value if no such element is found.

Declaration
public static TSource FirstOrDefault<TSource>(this IOpt<TSource> source, Func<TSource, bool> predicate, TSource defaultValue)
Parameters
Type Name Description
IOpt<TSource> source

An option to return an element from.

Func<TSource, Boolean> predicate

A function to test each element for a condition.

TSource defaultValue

A default value to return if source contains no elements that satisfy predicate.

Returns
Type Description
TSource

The first element of source that satisfies predicate, or defaultValue if no such element is found.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source or predicate is null.

| Improve this Doc View Source

Flatten<TSource>(IOpt<IOpt<TSource>>)

Collapses an option containing another option into a single option.

Declaration
public static IOpt<TSource> Flatten<TSource>(this IOpt<IOpt<TSource>> source)
Parameters
Type Name Description
IOpt<IOpt<TSource>> source

An outer option containing an inner option.

Returns
Type Description
IOpt<TSource>

An option equivalent to the inner option, if it exists; otherwise, an empty option.

Type Parameters
Name Description
TSource

The element type of the inner option.

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 (immediate) or the element of source is null (deferred).

| Improve this Doc View Source

Flatten<TSource>(IOpt<Opt<TSource>>)

Collapses an option containing another option into a single option.

Declaration
public static IOpt<TSource> Flatten<TSource>(this IOpt<Opt<TSource>> source)
Parameters
Type Name Description
IOpt<Opt<TSource>> source

An outer option containing an inner option.

Returns
Type Description
IOpt<TSource>

An option equivalent to the inner option, if it exists; otherwise, an empty option.

Type Parameters
Name Description
TSource

The element type of the inner option.

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.

| Improve this Doc View Source

GroupBy<TSource, TKey>(IOpt<TSource>, Func<TSource, TKey>)

Groups the elements of an option by a selected key.

Declaration
public static IOpt<IOptGrouping<TKey, TSource>> GroupBy<TSource, TKey>(this IOpt<TSource> source, Func<TSource, TKey> keySelector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, TKey> keySelector

A function to select the key that corresponds to an element.

Returns
Type Description
IOpt<IOptGrouping<TKey, TSource>>

An option that contains a grouping for the element of source, if source is full; otherwise, an empty option.

Type Parameters
Name Description
TSource

The type of the elements of source.

TKey

The type of the key used to group elements.

Exceptions
Type Condition
ArgumentNullException

source or keySelector is null.

| Improve this Doc View Source

GroupBy<TSource, TKey>(IOpt<TSource>, Func<TSource, TKey>, IEqualityComparer<TKey>)

Groups the elements of an option by a selected key.

Declaration
public static IOpt<IOptGrouping<TKey, TSource>> GroupBy<TSource, TKey>(this IOpt<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, TKey> keySelector

A function to select the key that corresponds to an element.

IEqualityComparer<TKey> comparer

A comparer to determine whether keys are equal. (This parameter is ignored.)

Returns
Type Description
IOpt<IOptGrouping<TKey, TSource>>

An option that contains a grouping for the element of source, if source is full; otherwise, an empty option.

Type Parameters
Name Description
TSource

The type of the elements of source.

TKey

The type of the key used to group elements.

Exceptions
Type Condition
ArgumentNullException

source or keySelector is null.

| Improve this Doc View Source

GroupBy<TSource, TKey, TElement>(IOpt<TSource>, Func<TSource, TKey>, Func<TSource, TElement>)

Groups the projected elements of an option by a selected key.

Declaration
public static IOpt<IOptGrouping<TKey, TElement>> GroupBy<TSource, TKey, TElement>(this IOpt<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, TKey> keySelector

A function to select the key that corresponds to an element of source.

Func<TSource, TElement> elementSelector

A function to transform an element of source to an element to include in a grouping.

Returns
Type Description
IOpt<IOptGrouping<TKey, TElement>>

An option that contains a grouping for the projected element of source, if source is full; otherwise, an empty option.

Type Parameters
Name Description
TSource

The type of the elements of source.

TKey

The type of the key used to group elements.

TElement

The type of the transformed elements to include in the grouping.

Exceptions
Type Condition
ArgumentNullException

source, keySelector, or elementSelector is null.

| Improve this Doc View Source

GroupBy<TSource, TKey, TElement>(IOpt<TSource>, Func<TSource, TKey>, Func<TSource, TElement>, IEqualityComparer<TKey>)

Groups the projected elements of an option by a selected key.

Declaration
public static IOpt<IOptGrouping<TKey, TElement>> GroupBy<TSource, TKey, TElement>(this IOpt<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, TKey> keySelector

A function to select the key that corresponds to an element of source.

Func<TSource, TElement> elementSelector

A function to transform an element of source to an element to include in a grouping.

IEqualityComparer<TKey> comparer

A comparer to determine whether keys are equal. (This parameter is ignored.)

Returns
Type Description
IOpt<IOptGrouping<TKey, TElement>>

An option that contains a grouping for the projected element of source, if source is full; otherwise, an empty option.

Type Parameters
Name Description
TSource

The type of the elements of source.

TKey

The type of the key used to group elements.

TElement

The type of the transformed elements to include in the grouping.

Exceptions
Type Condition
ArgumentNullException

source, keySelector, or elementSelector is null.

| Improve this Doc View Source

GroupBy<TSource, TKey, TResult>(IOpt<TSource>, Func<TSource, TKey>, Func<TKey, IOpt<TSource>, TResult>)

Groups the elements of an option by a selected key, then applies a transform to each grouping.

Declaration
public static IOpt<TResult> GroupBy<TSource, TKey, TResult>(this IOpt<TSource> source, Func<TSource, TKey> keySelector, Func<TKey, IOpt<TSource>, TResult> resultSelector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, TKey> keySelector

A function to select the key that corresponds to an element of source.

Func<TKey, IOpt<TSource>, TResult> resultSelector

A function to select a result value for each grouping.

Returns
Type Description
IOpt<TResult>

An option that contains the result of applying resultSelector to the grouping for the element of source, if source is full; otherwise, an empty option.

Type Parameters
Name Description
TSource

The type of the elements of source.

TKey

The type of the key used to group elements.

TResult

The type of the result value for each grouping.

Exceptions
Type Condition
ArgumentNullException

source, keySelector, or resultSelector is null.

| Improve this Doc View Source

GroupBy<TSource, TKey, TResult>(IOpt<TSource>, Func<TSource, TKey>, Func<TKey, IOpt<TSource>, TResult>, IEqualityComparer<TKey>)

Groups the elements of an option by a selected key, then applies a transform to each grouping.

Declaration
public static IOpt<TResult> GroupBy<TSource, TKey, TResult>(this IOpt<TSource> source, Func<TSource, TKey> keySelector, Func<TKey, IOpt<TSource>, TResult> resultSelector, IEqualityComparer<TKey> comparer)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, TKey> keySelector

A function to select the key that corresponds to an element of source.

Func<TKey, IOpt<TSource>, TResult> resultSelector

A function to select a result value for each grouping.

IEqualityComparer<TKey> comparer

A comparer to determine whether keys are equal. (This parameter is ignored.)

Returns
Type Description
IOpt<TResult>

An option that contains the result of applying resultSelector to the grouping for the element of source, if source is full; otherwise, an empty option.

Type Parameters
Name Description
TSource

The type of the elements of source.

TKey

The type of the key used to group elements.

TResult

The type of the result value for each grouping.

Exceptions
Type Condition
ArgumentNullException

source, keySelector, or resultSelector is null.

| Improve this Doc View Source

GroupBy<TSource, TKey, TElement, TResult>(IOpt<TSource>, Func<TSource, TKey>, Func<TSource, TElement>, Func<TKey, IOpt<TElement>, TResult>)

Groups the projected elements of an option by a selected key, then applies a transform to each grouping.

Declaration
public static IOpt<TResult> GroupBy<TSource, TKey, TElement, TResult>(this IOpt<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, Func<TKey, IOpt<TElement>, TResult> resultSelector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, TKey> keySelector

A function to select the key that corresponds to an element of source.

Func<TSource, TElement> elementSelector

A function to transform an element of source to an element to include in a grouping.

Func<TKey, IOpt<TElement>, TResult> resultSelector

A function to select a result value for each grouping.

Returns
Type Description
IOpt<TResult>

An option that contains the result of applying resultSelector to the grouping for the projected element of source, if source is full; otherwise, an empty option.

Type Parameters
Name Description
TSource

The type of the elements of source.

TKey

The type of the key used to group elements.

TElement

The type of the transformed elements to include in the grouping.

TResult

The type of the result value for each grouping.

Exceptions
Type Condition
ArgumentNullException

source, keySelector, elementSelector, or resultSelector is null.

| Improve this Doc View Source

GroupBy<TSource, TKey, TElement, TResult>(IOpt<TSource>, Func<TSource, TKey>, Func<TSource, TElement>, Func<TKey, IOpt<TElement>, TResult>, IEqualityComparer<TKey>)

Groups the projected elements of an option by a selected key, then applies a transform to each grouping.

Declaration
public static IOpt<TResult> GroupBy<TSource, TKey, TElement, TResult>(this IOpt<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, Func<TKey, IOpt<TElement>, TResult> resultSelector, IEqualityComparer<TKey> comparer)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, TKey> keySelector

A function to select the key that corresponds to an element of source.

Func<TSource, TElement> elementSelector

A function to transform an element of source to an element to include in a grouping.

Func<TKey, IOpt<TElement>, TResult> resultSelector

A function to select a result value for each grouping.

IEqualityComparer<TKey> comparer

A comparer to determine whether keys are equal. (This parameter is ignored.)

Returns
Type Description
IOpt<TResult>

An option that contains the result of applying resultSelector to the grouping for the projected element of source, if source is full; otherwise, an empty option.

Type Parameters
Name Description
TSource

The type of the elements of source.

TKey

The type of the key used to group elements.

TElement

The type of the transformed elements to include in the grouping.

TResult

The type of the result value for each grouping.

Exceptions
Type Condition
ArgumentNullException

source, keySelector, elementSelector, or resultSelector is null.

| Improve this Doc View Source

GroupJoin<TOuter, TInner, TKey, TResult>(IOpt<TOuter>, IOpt<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, IOpt<TInner>, TResult>)

Joins each element of an outer option to a grouping of inner elements with matching keys, then applies a transform to each grouping.

Declaration
public static IOpt<TResult> GroupJoin<TOuter, TInner, TKey, TResult>(this IOpt<TOuter> outer, IOpt<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, IOpt<TInner>, TResult> resultSelector)
Parameters
Type Name Description
IOpt<TOuter> outer

The outer option to join.

IOpt<TInner> inner

The inner option to join.

Func<TOuter, TKey> outerKeySelector

A function to select the key that corresponds to an element of outer.

Func<TInner, TKey> innerKeySelector

A function to select the key that corresponds to an element of inner.

Func<TOuter, IOpt<TInner>, TResult> resultSelector

A function to select a result value for each grouping.

Returns
Type Description
IOpt<TResult>

An option that contains the result of applying resultSelector to the grouping for the element of outer and its corresponding elements of inner, if outer is full; otherwise, an empty option.

Type Parameters
Name Description
TOuter

The type of the elements of outer.

TInner

The type of the elements of inner.

TKey

The type of the key used to match and group elements.

TResult

The type of the result value for each grouping.

Exceptions
Type Condition
ArgumentNullException

outer, inner, outerKeySelector, innerKeySelector, or resultSelector is null.

| Improve this Doc View Source

GroupJoin<TOuter, TInner, TKey, TResult>(IOpt<TOuter>, IOpt<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, IOpt<TInner>, TResult>, IEqualityComparer<TKey>)

Joins each element of an outer option to a grouping of inner elements with matching keys, then applies a transform to each grouping.

Declaration
public static IOpt<TResult> GroupJoin<TOuter, TInner, TKey, TResult>(this IOpt<TOuter> outer, IOpt<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, IOpt<TInner>, TResult> resultSelector, IEqualityComparer<TKey> comparer)
Parameters
Type Name Description
IOpt<TOuter> outer

The outer option to join.

IOpt<TInner> inner

The inner option to join.

Func<TOuter, TKey> outerKeySelector

A function to select the key that corresponds to an element of outer.

Func<TInner, TKey> innerKeySelector

A function to select the key that corresponds to an element of inner.

Func<TOuter, IOpt<TInner>, TResult> resultSelector

A function to select a result value for each grouping.

IEqualityComparer<TKey> comparer

A comparer to determine whether keys are equal. (If null, Default is used.)

Returns
Type Description
IOpt<TResult>

An option that contains the result of applying resultSelector to the grouping for the element of outer and its corresponding elements of inner, if outer is full; otherwise, an empty option.

Type Parameters
Name Description
TOuter

The type of the elements of outer.

TInner

The type of the elements of inner.

TKey

The type of the key used to match and group elements.

TResult

The type of the result value for each grouping.

Exceptions
Type Condition
ArgumentNullException

outer, inner, outerKeySelector, innerKeySelector, or resultSelector is null.

| Improve this Doc View Source

GroupJoin<TOuter, TInner, TKey, TResult>(IOpt<TOuter>, IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, IEnumerable<TInner>, TResult>)

Joins each element of an outer option to a grouping of inner elements with matching keys, then applies a transform to each grouping.

Declaration
public static IOpt<TResult> GroupJoin<TOuter, TInner, TKey, TResult>(this IOpt<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, IEnumerable<TInner>, TResult> resultSelector)
Parameters
Type Name Description
IOpt<TOuter> outer

The outer option to join.

IEnumerable<TInner> inner

The inner sequence to join.

Func<TOuter, TKey> outerKeySelector

A function to select the key that corresponds to an element of outer.

Func<TInner, TKey> innerKeySelector

A function to select the key that corresponds to an element of inner.

Func<TOuter, IEnumerable<TInner>, TResult> resultSelector

A function to select a result value for each grouping.

Returns
Type Description
IOpt<TResult>

An option that contains the result of applying resultSelector to the grouping for the element of outer and its corresponding elements of inner, if outer is full; otherwise, an empty option.

Type Parameters
Name Description
TOuter

The type of the elements of outer.

TInner

The type of the elements of inner.

TKey

The type of the key used to match and group elements.

TResult

The type of the result value for each grouping.

Exceptions
Type Condition
ArgumentNullException

outer, inner, outerKeySelector, innerKeySelector, or resultSelector is null.

| Improve this Doc View Source

GroupJoin<TOuter, TInner, TKey, TResult>(IOpt<TOuter>, IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, IEnumerable<TInner>, TResult>, IEqualityComparer<TKey>)

Joins each element of an outer option to a grouping of inner elements with matching keys, then applies a transform to each grouping.

Declaration
public static IOpt<TResult> GroupJoin<TOuter, TInner, TKey, TResult>(this IOpt<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, IEnumerable<TInner>, TResult> resultSelector, IEqualityComparer<TKey> comparer)
Parameters
Type Name Description
IOpt<TOuter> outer

The outer option to join.

IEnumerable<TInner> inner

The inner sequence to join.

Func<TOuter, TKey> outerKeySelector

A function to select the key that corresponds to an element of outer.

Func<TInner, TKey> innerKeySelector

A function to select the key that corresponds to an element of inner.

Func<TOuter, IEnumerable<TInner>, TResult> resultSelector

A function to select a result value for each grouping.

IEqualityComparer<TKey> comparer

A comparer to determine whether keys are equal. (If null, Default is used.)

Returns
Type Description
IOpt<TResult>

An option that contains the result of applying resultSelector to the grouping for the element of outer and its corresponding elements of inner, if outer is full; otherwise, an empty option.

Type Parameters
Name Description
TOuter

The type of the elements of outer.

TInner

The type of the elements of inner.

TKey

The type of the key used to match and group elements.

TResult

The type of the result value for each grouping.

Exceptions
Type Condition
ArgumentNullException

outer, inner, outerKeySelector, innerKeySelector, or resultSelector is null.

| Improve this Doc View Source

Intersect<TSource>(IOpt<TSource>, IEnumerable<TSource>)

Finds the elements of an option that also appear in a sequence.

Declaration
public static IOpt<TSource> Intersect<TSource>(this IOpt<TSource> first, IEnumerable<TSource> second)
Parameters
Type Name Description
IOpt<TSource> first

An option whose elements are to be compared.

IEnumerable<TSource> second

A sequence of elements to be compared.

Returns
Type Description
IOpt<TSource>

An option equivalent to first, if the element of first appears in second; otherwise, an empty option.

Type Parameters
Name Description
TSource

The type of the elements of first and second.

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

first or second is null.

| Improve this Doc View Source

Intersect<TSource>(IOpt<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>)

Finds the elements of an option that also appear in a sequence, using the specified comparer to determine equality.

Declaration
public static IOpt<TSource> Intersect<TSource>(this IOpt<TSource> first, IEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
Parameters
Type Name Description
IOpt<TSource> first

An option whose elements are to be compared.

IEnumerable<TSource> second

A sequence of elements to be compared.

IEqualityComparer<TSource> comparer

A comparer to determine whether elements are equal. (If null, Default is used.)

Returns
Type Description
IOpt<TSource>

An option equivalent to first, if the element of first appears in second; otherwise, an empty option.

Type Parameters
Name Description
TSource

The type of the elements of first and second.

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

first or second is null.

| Improve this Doc View Source

Join<TOuter, TInner, TKey, TResult>(IOpt<TOuter>, IOpt<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, TInner, TResult>)

Joins elements of an outer option with elements of an inner option having matching keys.

Declaration
public static IOpt<TResult> Join<TOuter, TInner, TKey, TResult>(this IOpt<TOuter> outer, IOpt<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, TInner, TResult> resultSelector)
Parameters
Type Name Description
IOpt<TOuter> outer

The outer option to join.

IOpt<TInner> inner

The inner option to join.

Func<TOuter, TKey> outerKeySelector

A function to select the key that corresponds to an element of outer.

Func<TInner, TKey> innerKeySelector

A function to select the key that corresponds to an element of inner.

Func<TOuter, TInner, TResult> resultSelector

A function to select a result value for each matched pair.

Returns
Type Description
IOpt<TResult>

An option that contains the result of applying resultSelector to the element of outer and the element of inner, if both options are full and their corresponding keys are equal; otherwise, an empty option.

Type Parameters
Name Description
TOuter

The type of the elements of outer.

TInner

The type of the elements of inner.

TKey

The type of the key used to match elements.

TResult

The type of the result value for each matched pair.

Exceptions
Type Condition
ArgumentNullException

outer, inner, outerKeySelector, innerKeySelector, or resultSelector is null.

| Improve this Doc View Source

Join<TOuter, TInner, TKey, TResult>(IOpt<TOuter>, IOpt<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, TInner, TResult>, IEqualityComparer<TKey>)

Joins elements of an outer option with elements of an inner option having matching keys.

Declaration
public static IOpt<TResult> Join<TOuter, TInner, TKey, TResult>(this IOpt<TOuter> outer, IOpt<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, TInner, TResult> resultSelector, IEqualityComparer<TKey> comparer)
Parameters
Type Name Description
IOpt<TOuter> outer

The outer option to join.

IOpt<TInner> inner

The inner option to join.

Func<TOuter, TKey> outerKeySelector

A function to select the key that corresponds to an element of outer.

Func<TInner, TKey> innerKeySelector

A function to select the key that corresponds to an element of inner.

Func<TOuter, TInner, TResult> resultSelector

A function to select a result value for each matched pair.

IEqualityComparer<TKey> comparer

A comparer to determine whether keys are equal. (If null, Default is used.)

Returns
Type Description
IOpt<TResult>

An option that contains the result of applying resultSelector to the element of outer and the element of inner, if both options are full and their corresponding keys are equal according to comparer; otherwise, an empty option.

Type Parameters
Name Description
TOuter

The type of the elements of outer.

TInner

The type of the elements of inner.

TKey

The type of the key used to match elements.

TResult

The type of the result value for each matched pair.

Exceptions
Type Condition
ArgumentNullException

outer, inner, outerKeySelector, innerKeySelector, or resultSelector is null.

| Improve this Doc View Source

Last<TSource>(IOpt<TSource>)

Returns the first element of an option.

Declaration
public static TSource Last<TSource>(this IOpt<TSource> source)
Parameters
Type Name Description
IOpt<TSource> source

An option to return an element from.

Returns
Type Description
TSource

The first element of source.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Last<TSource>(IOpt<TSource>, Func<TSource, Boolean>)

Returns the first element of an option that satisfies a condition.

Declaration
public static TSource Last<TSource>(this IOpt<TSource> source, Func<TSource, bool> predicate)
Parameters
Type Name Description
IOpt<TSource> source

An option to return an element from.

Func<TSource, Boolean> predicate

A function to test each element for a condition.

Returns
Type Description
TSource

The first element of source that satisfies predicate.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source does not contain any element that satisfies predicate.

| Improve this Doc View Source

LastOrDefault<TSource>(IOpt<TSource>)

Returns the first element of an option, or the default value for the type if the option is empty.

Declaration
public static TSource LastOrDefault<TSource>(this IOpt<TSource> source)
Parameters
Type Name Description
IOpt<TSource> source

An option to return an element from.

Returns
Type Description
TSource

The first element of source, or the default value for TSource if source is empty.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

LastOrDefault<TSource>(IOpt<TSource>, TSource)

Returns the first element of an option, or a specified default value if the option is empty.

Declaration
public static TSource LastOrDefault<TSource>(this IOpt<TSource> source, TSource defaultValue)
Parameters
Type Name Description
IOpt<TSource> source

An option to return an element from.

TSource defaultValue

A default value to return if source contains no elements.

Returns
Type Description
TSource

The first element of source, or defaultValue if source is empty.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

LastOrDefault<TSource>(IOpt<TSource>, Func<TSource, Boolean>)

Returns the first element of an option that satisfies a condition, or the default value for the type if no such element is found.

Declaration
public static TSource LastOrDefault<TSource>(this IOpt<TSource> source, Func<TSource, bool> predicate)
Parameters
Type Name Description
IOpt<TSource> source

An option to return an element from.

Func<TSource, Boolean> predicate

A function to test each element for a condition.

Returns
Type Description
TSource

The first element of source that satisfies predicate, or the default value for TSource if no such element is found.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source or predicate is null.

| Improve this Doc View Source

LastOrDefault<TSource>(IOpt<TSource>, Func<TSource, Boolean>, TSource)

Returns the first element of an option that satisfies a condition, or a specified default value if no such element is found.

Declaration
public static TSource LastOrDefault<TSource>(this IOpt<TSource> source, Func<TSource, bool> predicate, TSource defaultValue)
Parameters
Type Name Description
IOpt<TSource> source

An option to return an element from.

Func<TSource, Boolean> predicate

A function to test each element for a condition.

TSource defaultValue

A default value to return if source contains no elements that satisfy predicate.

Returns
Type Description
TSource

The first element of source that satisfies predicate, or defaultValue if no such element is found.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source or predicate is null.

| Improve this Doc View Source

LongCount<TSource>(IOpt<TSource>)

Returns the number of elements in an option.

Declaration
public static long LongCount<TSource>(this IOpt<TSource> source)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Returns
Type Description
Int64

1 if source contains an element; otherwise, 0.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

LongCount<TSource>(IOpt<TSource>, Func<TSource, Boolean>)

Returns the number of elements of an option that satisfy a predicate.

Declaration
public static long LongCount<TSource>(this IOpt<TSource> source, Func<TSource, bool> predicate)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Boolean> predicate

A function to test each element for a condition.

Returns
Type Description
Int64

1, if source contains an element that satisfies predicate; otherwise, 0.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source or predicate is null.

| Improve this Doc View Source

Match<TSource, TResult>(IOpt<TSource>, Func<TResult>, Func<TSource, TResult>)

Converts this option to another value based on its contents.

Declaration
public static TResult Match<TSource, TResult>(this IOpt<TSource> source, Func<TResult> ifEmpty = null, Func<TSource, TResult> ifFull = null)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TResult> ifEmpty

A function to produce the result if this option is empty.

Func<TSource, TResult> ifFull

A function to produce the result if this option is full, which accepts the contained element as a parameter.

Returns
Type Description
TResult

The result of calling ifEmpty, if this option is empty; otherwise, the result of calling ifFull.

Type Parameters
Name Description
TSource

The element type of source.

TResult

The result type for this conversion.

Remarks

This operation is performed immediately rather than by deferred execution. Compare MatchOpt<TSource, TResult>(IOpt<TSource>, Func<Opt<TResult>>, Func<TSource, Opt<TResult>>), which uses deferred execution.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

ifEmpty is null and this option is empty, or ifFull is null and this option is full.

| Improve this Doc View Source

MatchOpt<TSource, TResult>(IOpt<TSource>, Func<Opt<TResult>>, Func<TSource, Opt<TResult>>)

Converts this option to another option based on its contents.

Declaration
public static IOpt<TResult> MatchOpt<TSource, TResult>(this IOpt<TSource> source, Func<Opt<TResult>> ifEmpty = null, Func<TSource, Opt<TResult>> ifFull = null)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<Opt<TResult>> ifEmpty

A function to produce the result if this option is empty.

Func<TSource, Opt<TResult>> ifFull

A function to produce the result if this option is full, which accepts the contained element as a parameter.

Returns
Type Description
IOpt<TResult>

An option equivalent to the result of calling ifEmpty, if this option is empty; otherwise, an option equivalent to the result of calling ifFull.

Type Parameters
Name Description
TSource

The element type of source.

TResult

The element type for the result of 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.

Compare Match<TSource, TResult>(IOpt<TSource>, Func<TResult>, Func<TSource, TResult>), which uses immediate execution.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

ifEmpty is null and this option is empty, or ifFull is null and this option is full.

| Improve this Doc View Source

Max(IOpt<Decimal>)

Returns the maximum value in an option.

Declaration
public static decimal Max(this IOpt<decimal> source)
Parameters
Type Name Description
IOpt<Decimal> source

A source option.

Returns
Type Description
Decimal

The only element of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Max(IOpt<Double>)

Returns the maximum value in an option.

Declaration
public static double Max(this IOpt<double> source)
Parameters
Type Name Description
IOpt<Double> source

A source option.

Returns
Type Description
Double

The only element of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Max(IOpt<Int32>)

Returns the maximum value in an option.

Declaration
public static int Max(this IOpt<int> source)
Parameters
Type Name Description
IOpt<Int32> source

A source option.

Returns
Type Description
Int32

The only element of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Max(IOpt<Int64>)

Returns the maximum value in an option.

Declaration
public static long Max(this IOpt<long> source)
Parameters
Type Name Description
IOpt<Int64> source

A source option.

Returns
Type Description
Int64

The only element of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Max(IOpt<Nullable<Decimal>>)

Returns the maximum value in an option.

Declaration
public static decimal? Max(this IOpt<decimal? > source)
Parameters
Type Name Description
IOpt<Nullable<Decimal>> source

A source option.

Returns
Type Description
Nullable<Decimal>

The only element of source, if source contains a value; otherwise, null.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Max(IOpt<Nullable<Double>>)

Returns the maximum value in an option.

Declaration
public static double? Max(this IOpt<double? > source)
Parameters
Type Name Description
IOpt<Nullable<Double>> source

A source option.

Returns
Type Description
Nullable<Double>

The only element of source, if source contains a value; otherwise, null.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Max(IOpt<Nullable<Int32>>)

Returns the maximum value in an option.

Declaration
public static int? Max(this IOpt<int? > source)
Parameters
Type Name Description
IOpt<Nullable<Int32>> source

A source option.

Returns
Type Description
Nullable<Int32>

The only element of source, if source contains a value; otherwise, null.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Max(IOpt<Nullable<Int64>>)

Returns the maximum value in an option.

Declaration
public static long? Max(this IOpt<long? > source)
Parameters
Type Name Description
IOpt<Nullable<Int64>> source

A source option.

Returns
Type Description
Nullable<Int64>

The only element of source, if source contains a value; otherwise, null.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Max(IOpt<Nullable<Single>>)

Returns the maximum value in an option.

Declaration
public static float? Max(this IOpt<float? > source)
Parameters
Type Name Description
IOpt<Nullable<Single>> source

A source option.

Returns
Type Description
Nullable<Single>

The only element of source, if source contains a value; otherwise, null.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Max(IOpt<Single>)

Returns the maximum value in an option.

Declaration
public static float Max(this IOpt<float> source)
Parameters
Type Name Description
IOpt<Single> source

A source option.

Returns
Type Description
Single

The only element of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Max<TSource>(IOpt<TSource>)

Returns the maximum value in an option.

Declaration
public static TSource Max<TSource>(this IOpt<TSource> source)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Returns
Type Description
TSource

The only element of source, if source contains a value; otherwise, null, if null is an allowed value for TSource.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty and null is not an allowed value for TSource.

| Improve this Doc View Source

Max<TSource>(IOpt<TSource>, Func<TSource, Decimal>)

Returns the maximum value in the projection of an option.

Declaration
public static decimal Max<TSource>(this IOpt<TSource> source, Func<TSource, decimal> selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Decimal> selector

A transform function applied to each element of source.

Returns
Type Description
Decimal

The result of applying selector to the only element of source.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Max<TSource>(IOpt<TSource>, Func<TSource, Double>)

Returns the maximum value in the projection of an option.

Declaration
public static double Max<TSource>(this IOpt<TSource> source, Func<TSource, double> selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Double> selector

A transform function applied to each element of source.

Returns
Type Description
Double

The result of applying selector to the only element of source.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Max<TSource>(IOpt<TSource>, Func<TSource, Int32>)

Returns the maximum value in the projection of an option.

Declaration
public static int Max<TSource>(this IOpt<TSource> source, Func<TSource, int> selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Int32> selector

A transform function applied to each element of source.

Returns
Type Description
Int32

The result of applying selector to the only element of source.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Max<TSource>(IOpt<TSource>, Func<TSource, Int64>)

Returns the maximum value in the projection of an option.

Declaration
public static long Max<TSource>(this IOpt<TSource> source, Func<TSource, long> selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Int64> selector

A transform function applied to each element of source.

Returns
Type Description
Int64

The result of applying selector to the only element of source.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Max<TSource>(IOpt<TSource>, Func<TSource, Nullable<Decimal>>)

Returns the maximum value in the projection of an option.

Declaration
public static decimal? Max<TSource>(this IOpt<TSource> source, Func<TSource, decimal? > selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Nullable<Decimal>> selector

A transform function applied to each element of source.

Returns
Type Description
Nullable<Decimal>

The result of applying selector to the only element of source, if source contains a value; otherwise, null.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Max<TSource>(IOpt<TSource>, Func<TSource, Nullable<Double>>)

Returns the maximum value in the projection of an option.

Declaration
public static double? Max<TSource>(this IOpt<TSource> source, Func<TSource, double? > selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Nullable<Double>> selector

A transform function applied to each element of source.

Returns
Type Description
Nullable<Double>

The result of applying selector to the only element of source, if source contains a value; otherwise, null.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Max<TSource>(IOpt<TSource>, Func<TSource, Nullable<Int32>>)

Returns the maximum value in the projection of an option.

Declaration
public static int? Max<TSource>(this IOpt<TSource> source, Func<TSource, int? > selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Nullable<Int32>> selector

A transform function applied to each element of source.

Returns
Type Description
Nullable<Int32>

The result of applying selector to the only element of source, if source contains a value; otherwise, null.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Max<TSource>(IOpt<TSource>, Func<TSource, Nullable<Int64>>)

Returns the maximum value in the projection of an option.

Declaration
public static long? Max<TSource>(this IOpt<TSource> source, Func<TSource, long? > selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Nullable<Int64>> selector

A transform function applied to each element of source.

Returns
Type Description
Nullable<Int64>

The result of applying selector to the only element of source, if source contains a value; otherwise, null.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Max<TSource>(IOpt<TSource>, Func<TSource, Nullable<Single>>)

Returns the maximum value in the projection of an option.

Declaration
public static float? Max<TSource>(this IOpt<TSource> source, Func<TSource, float? > selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Nullable<Single>> selector

A transform function applied to each element of source.

Returns
Type Description
Nullable<Single>

The result of applying selector to the only element of source, if source contains a value; otherwise, null.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Max<TSource>(IOpt<TSource>, Func<TSource, Single>)

Returns the maximum value in the projection of an option.

Declaration
public static float Max<TSource>(this IOpt<TSource> source, Func<TSource, float> selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Single> selector

A transform function applied to each element of source.

Returns
Type Description
Single

The result of applying selector to the only element of source.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Max<TSource, TResult>(IOpt<TSource>, Func<TSource, TResult>)

Returns the maximum value in the projection of an option.

Declaration
public static TResult Max<TSource, TResult>(this IOpt<TSource> source, Func<TSource, TResult> selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, TResult> selector

A transform function applied to each element of source.

Returns
Type Description
TResult

The result of applying selector to the only element of source, if source contains a value; otherwise, null, if null is an allowed value for TResult.

Type Parameters
Name Description
TSource

The type of the elements of source.

TResult
Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty and null is not an allowed value for TResult.

| Improve this Doc View Source

Min(IOpt<Decimal>)

Returns the minimum value in an option.

Declaration
public static decimal Min(this IOpt<decimal> source)
Parameters
Type Name Description
IOpt<Decimal> source

A source option.

Returns
Type Description
Decimal

The only element of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Min(IOpt<Double>)

Returns the minimum value in an option.

Declaration
public static double Min(this IOpt<double> source)
Parameters
Type Name Description
IOpt<Double> source

A source option.

Returns
Type Description
Double

The only element of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Min(IOpt<Int32>)

Returns the minimum value in an option.

Declaration
public static int Min(this IOpt<int> source)
Parameters
Type Name Description
IOpt<Int32> source

A source option.

Returns
Type Description
Int32

The only element of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Min(IOpt<Int64>)

Returns the minimum value in an option.

Declaration
public static long Min(this IOpt<long> source)
Parameters
Type Name Description
IOpt<Int64> source

A source option.

Returns
Type Description
Int64

The only element of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Min(IOpt<Nullable<Decimal>>)

Returns the minimum value in an option.

Declaration
public static decimal? Min(this IOpt<decimal? > source)
Parameters
Type Name Description
IOpt<Nullable<Decimal>> source

A source option.

Returns
Type Description
Nullable<Decimal>

The only element of source, if source contains a value; otherwise, null.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Min(IOpt<Nullable<Double>>)

Returns the minimum value in an option.

Declaration
public static double? Min(this IOpt<double? > source)
Parameters
Type Name Description
IOpt<Nullable<Double>> source

A source option.

Returns
Type Description
Nullable<Double>

The only element of source, if source contains a value; otherwise, null.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Min(IOpt<Nullable<Int32>>)

Returns the minimum value in an option.

Declaration
public static int? Min(this IOpt<int? > source)
Parameters
Type Name Description
IOpt<Nullable<Int32>> source

A source option.

Returns
Type Description
Nullable<Int32>

The only element of source, if source contains a value; otherwise, null.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Min(IOpt<Nullable<Int64>>)

Returns the minimum value in an option.

Declaration
public static long? Min(this IOpt<long? > source)
Parameters
Type Name Description
IOpt<Nullable<Int64>> source

A source option.

Returns
Type Description
Nullable<Int64>

The only element of source, if source contains a value; otherwise, null.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Min(IOpt<Nullable<Single>>)

Returns the minimum value in an option.

Declaration
public static float? Min(this IOpt<float? > source)
Parameters
Type Name Description
IOpt<Nullable<Single>> source

A source option.

Returns
Type Description
Nullable<Single>

The only element of source, if source contains a value; otherwise, null.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Min(IOpt<Single>)

Returns the minimum value in an option.

Declaration
public static float Min(this IOpt<float> source)
Parameters
Type Name Description
IOpt<Single> source

A source option.

Returns
Type Description
Single

The only element of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Min<TSource>(IOpt<TSource>)

Returns the minimum value in an option.

Declaration
public static TSource Min<TSource>(this IOpt<TSource> source)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Returns
Type Description
TSource

The only element of source, if source contains a value; otherwise, null, if null is an allowed value for TSource.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty and null is not an allowed value for TSource.

| Improve this Doc View Source

Min<TSource>(IOpt<TSource>, Func<TSource, Decimal>)

Returns the minimum value in the projection of an option.

Declaration
public static decimal Min<TSource>(this IOpt<TSource> source, Func<TSource, decimal> selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Decimal> selector

A transform function applied to each element of source.

Returns
Type Description
Decimal

The result of applying selector to the only element of source.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Min<TSource>(IOpt<TSource>, Func<TSource, Double>)

Returns the minimum value in the projection of an option.

Declaration
public static double Min<TSource>(this IOpt<TSource> source, Func<TSource, double> selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Double> selector

A transform function applied to each element of source.

Returns
Type Description
Double

The result of applying selector to the only element of source.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Min<TSource>(IOpt<TSource>, Func<TSource, Int32>)

Returns the minimum value in the projection of an option.

Declaration
public static int Min<TSource>(this IOpt<TSource> source, Func<TSource, int> selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Int32> selector

A transform function applied to each element of source.

Returns
Type Description
Int32

The result of applying selector to the only element of source.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Min<TSource>(IOpt<TSource>, Func<TSource, Int64>)

Returns the minimum value in the projection of an option.

Declaration
public static long Min<TSource>(this IOpt<TSource> source, Func<TSource, long> selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Int64> selector

A transform function applied to each element of source.

Returns
Type Description
Int64

The result of applying selector to the only element of source.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Min<TSource>(IOpt<TSource>, Func<TSource, Nullable<Decimal>>)

Returns the minimum value in the projection of an option.

Declaration
public static decimal? Min<TSource>(this IOpt<TSource> source, Func<TSource, decimal? > selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Nullable<Decimal>> selector

A transform function applied to each element of source.

Returns
Type Description
Nullable<Decimal>

The result of applying selector to the only element of source, if source contains a value; otherwise, null.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Min<TSource>(IOpt<TSource>, Func<TSource, Nullable<Double>>)

Returns the minimum value in the projection of an option.

Declaration
public static double? Min<TSource>(this IOpt<TSource> source, Func<TSource, double? > selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Nullable<Double>> selector

A transform function applied to each element of source.

Returns
Type Description
Nullable<Double>

The result of applying selector to the only element of source, if source contains a value; otherwise, null.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Min<TSource>(IOpt<TSource>, Func<TSource, Nullable<Int32>>)

Returns the minimum value in the projection of an option.

Declaration
public static int? Min<TSource>(this IOpt<TSource> source, Func<TSource, int? > selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Nullable<Int32>> selector

A transform function applied to each element of source.

Returns
Type Description
Nullable<Int32>

The result of applying selector to the only element of source, if source contains a value; otherwise, null.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Min<TSource>(IOpt<TSource>, Func<TSource, Nullable<Int64>>)

Returns the minimum value in the projection of an option.

Declaration
public static long? Min<TSource>(this IOpt<TSource> source, Func<TSource, long? > selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Nullable<Int64>> selector

A transform function applied to each element of source.

Returns
Type Description
Nullable<Int64>

The result of applying selector to the only element of source, if source contains a value; otherwise, null.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Min<TSource>(IOpt<TSource>, Func<TSource, Nullable<Single>>)

Returns the minimum value in the projection of an option.

Declaration
public static float? Min<TSource>(this IOpt<TSource> source, Func<TSource, float? > selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Nullable<Single>> selector

A transform function applied to each element of source.

Returns
Type Description
Nullable<Single>

The result of applying selector to the only element of source, if source contains a value; otherwise, null.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Min<TSource>(IOpt<TSource>, Func<TSource, Single>)

Returns the minimum value in the projection of an option.

Declaration
public static float Min<TSource>(this IOpt<TSource> source, Func<TSource, float> selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Single> selector

A transform function applied to each element of source.

Returns
Type Description
Single

The result of applying selector to the only element of source.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Min<TSource, TResult>(IOpt<TSource>, Func<TSource, TResult>)

Returns the minimum value in the projection of an option.

Declaration
public static TResult Min<TSource, TResult>(this IOpt<TSource> source, Func<TSource, TResult> selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, TResult> selector

A transform function applied to each element of source.

Returns
Type Description
TResult

The result of applying selector to the only element of source, if source contains a value; otherwise, null, if null is an allowed value for TResult.

Type Parameters
Name Description
TSource

The type of the elements of source.

TResult
Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty and null is not an allowed value for TResult.

| Improve this Doc View Source

OfType<TResult>(IOpt)

Filters the elements of an option to those of a specified type.

Declaration
public static IOpt<TResult> OfType<TResult>(this IOpt source)
Parameters
Type Name Description
IOpt source

A source option.

Returns
Type Description
IOpt<TResult>

An option having the same contents as source, if it contains an element that is of type TResult (according to the langword_csharp_is operator); otherwise, an empty option.

Type Parameters
Name Description
TResult

The type to which to filter the elements of source.

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.

| Improve this Doc View Source

OrderBy<TSource, TKey>(IOpt<TSource>, Func<TSource, TKey>)

Sorts the elements of an option in ascending order.

Declaration
public static IOpt<TSource> OrderBy<TSource, TKey>(this IOpt<TSource> source, Func<TSource, TKey> keySelector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, TKey> keySelector

A function to select the key that corresponds to an element of source.

Returns
Type Description
IOpt<TSource>

source.

Type Parameters
Name Description
TSource

The type of the elements of source.

TKey

The type of the key used to compare elements.

Remarks

Since an option, by virtue of being a zero- or one-element sequence, is trivially already ordered, this method returns source unmodified (after null-checking any required parameters).

Exceptions
Type Condition
ArgumentNullException

source or keySelector is null.

| Improve this Doc View Source

OrderBy<TSource, TKey>(IOpt<TSource>, Func<TSource, TKey>, IComparer<TKey>)

Sorts the elements of an option in ascending order.

Declaration
public static IOpt<TSource> OrderBy<TSource, TKey>(this IOpt<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey> comparer)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, TKey> keySelector

A function to select the key that corresponds to an element of source.

IComparer<TKey> comparer

A comparer used to order keys. (This parameter is ignored.)

Returns
Type Description
IOpt<TSource>

source.

Type Parameters
Name Description
TSource

The type of the elements of source.

TKey

The type of the key used to compare elements.

Remarks

Since an option, by virtue of being a zero- or one-element sequence, is trivially already ordered, this method returns source unmodified (after null-checking any required parameters).

Exceptions
Type Condition
ArgumentNullException

source or keySelector is null.

| Improve this Doc View Source

OrderByDescending<TSource, TKey>(IOpt<TSource>, Func<TSource, TKey>)

Sorts the elements of an option in descending order.

Declaration
public static IOpt<TSource> OrderByDescending<TSource, TKey>(this IOpt<TSource> source, Func<TSource, TKey> keySelector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, TKey> keySelector

A function to select the key that corresponds to an element of source.

Returns
Type Description
IOpt<TSource>

source.

Type Parameters
Name Description
TSource

The type of the elements of source.

TKey

The type of the key used to compare elements.

Remarks

Since an option, by virtue of being a zero- or one-element sequence, is trivially already ordered, this method returns source unmodified (after null-checking any required parameters).

Exceptions
Type Condition
ArgumentNullException

source or keySelector is null.

| Improve this Doc View Source

OrderByDescending<TSource, TKey>(IOpt<TSource>, Func<TSource, TKey>, IComparer<TKey>)

Sorts the elements of an option in descending order.

Declaration
public static IOpt<TSource> OrderByDescending<TSource, TKey>(this IOpt<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey> comparer)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, TKey> keySelector

A function to select the key that corresponds to an element of source.

IComparer<TKey> comparer

A comparer used to order keys. (This parameter is ignored.)

Returns
Type Description
IOpt<TSource>

source.

Type Parameters
Name Description
TSource

The type of the elements of source.

TKey

The type of the key used to compare elements.

Remarks

Since an option, by virtue of being a zero- or one-element sequence, is trivially already ordered, this method returns source unmodified (after null-checking any required parameters).

Exceptions
Type Condition
ArgumentNullException

source or keySelector is null.

| Improve this Doc View Source

ReplaceIfEmpty<TSource>(IOpt<TSource>, IOpt<TSource>)

Substitutes the specified replacement option if this option is empty.

Declaration
public static IOpt<TSource> ReplaceIfEmpty<TSource>(this IOpt<TSource> source, IOpt<TSource> replacement)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

IOpt<TSource> replacement

An option to produce the result if source is empty.

Returns
Type Description
IOpt<TSource>

An option equivalent to source, if it is full; 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

ReplaceIfEmpty<TSource>(IOpt<TSource>, Func<IOpt<TSource>>)

Substitutes the result of a callback if this option is empty.

Declaration
public static IOpt<TSource> ReplaceIfEmpty<TSource>(this IOpt<TSource> source, Func<IOpt<TSource>> replacementFactory)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<IOpt<TSource>> replacementFactory

A function to produce the result if source is empty.

Returns
Type Description
IOpt<TSource>

An option equivalent to source, if it is full; 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.

| Improve this Doc View Source

Reverse<TSource>(IOpt<TSource>)

Inverts the order of contents of an option.

Declaration
public static IOpt<TSource> Reverse<TSource>(this IOpt<TSource> source)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Returns
Type Description
IOpt<TSource>

source.

Type Parameters
Name Description
TSource

The type of the elements of source.

Remarks

Since an option, by virtue of being a zero- or one-element sequence, is its own reverse, this method returns source unmodified (after ensuring that it is not null).

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Select<TSource, TResult>(IOpt<TSource>, Func<TSource, TResult>)

Produces a projection of an option by applying a transformation function to its contents.

Declaration
public static IOpt<TResult> Select<TSource, TResult>(this IOpt<TSource> source, Func<TSource, TResult> selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, TResult> selector

A transform function applied to each element of source.

Returns
Type Description
IOpt<TResult>

A full option containing the result of applying selector to the element of source, if source is full; otherwise, an empty option.

Type Parameters
Name Description
TSource

The type of the elements of source.

TResult

The type of the elements of the result option.

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 or selector is null.

| Improve this Doc View Source

Select<TSource, TResult>(IOpt<TSource>, Func<TSource, Int32, TResult>)

Produces a projection of an option by applying a transformation function to its contents.

Declaration
public static IOpt<TResult> Select<TSource, TResult>(this IOpt<TSource> source, Func<TSource, int, TResult> selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Int32, TResult> selector

A transform function applied to each element of source and its index.

Returns
Type Description
IOpt<TResult>

A full option containing the result of applying selector to the element of source and its index, if source is full; otherwise, an empty option.

Type Parameters
Name Description
TSource

The type of the elements of source.

TResult

The type of the elements of the result option.

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 or selector is null.

| Improve this Doc View Source

SelectMany<TSource, TResult>(IOpt<TSource>, Func<TSource, IOpt<TResult>>)

Projects each element of an option to a new option and flattens the result.

Declaration
public static IOpt<TResult> SelectMany<TSource, TResult>(this IOpt<TSource> source, Func<TSource, IOpt<TResult>> selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, IOpt<TResult>> selector

A transform function applied to each element of source.

Returns
Type Description
IOpt<TResult>

A full option equivalent to the result of applying selector to the element of source, if source is full; otherwise, an empty option.

Type Parameters
Name Description
TSource

The type of the elements of source.

TResult

The type of the elements of the option returned by selector.

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 or selector is null.

| Improve this Doc View Source

SelectMany<TSource, TResult>(IOpt<TSource>, Func<TSource, Int32, IOpt<TResult>>)

Projects each element of an option to a new option and flattens the result.

Declaration
public static IOpt<TResult> SelectMany<TSource, TResult>(this IOpt<TSource> source, Func<TSource, int, IOpt<TResult>> selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Int32, IOpt<TResult>> selector

A transform function applied to each element of source and its index.

Returns
Type Description
IOpt<TResult>

A full option equivalent to the result of applying selector to the element of source and its index, if source is full; otherwise, an empty option.

Type Parameters
Name Description
TSource

The type of the elements of source.

TResult

The type of the elements of the option returned by selector.

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 or selector is null.

| Improve this Doc View Source

SelectMany<TSource, TCollection, TResult>(IOpt<TSource>, Func<TSource, IOpt<TCollection>>, Func<TSource, TCollection, TResult>)

Projects each element of an option to a new option and flattens the result, then applies a transform to the result elements.

Declaration
public static IOpt<TResult> SelectMany<TSource, TCollection, TResult>(this IOpt<TSource> source, Func<TSource, IOpt<TCollection>> collectionSelector, Func<TSource, TCollection, TResult> resultSelector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, IOpt<TCollection>> collectionSelector

A transform function applied to each element of source.

Func<TSource, TCollection, TResult> resultSelector

A transform function applied to each element of each intermediate option returned by collectionSelector and its corresponding element from source.

Returns
Type Description
IOpt<TResult>

A full option containing the result of applying resultSelector to the element of source and the element of the intermediate option produced by applying collectionSelector to the element of source, if source is full and the intermediate option is also full; otherwise, an empty option.

Type Parameters
Name Description
TSource

The type of the elements of source.

TCollection

The type of the elements of the intermediate option produced by applying collectionSelector to an element of source.

TResult

The type of the elements of the result option.

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, collectionSelector, or resultSelector is null.

| Improve this Doc View Source

SelectMany<TSource, TCollection, TResult>(IOpt<TSource>, Func<TSource, Int32, IOpt<TCollection>>, Func<TSource, TCollection, TResult>)

Projects each element of an option to a new option and flattens the result, then applies a transform to the result elements.

Declaration
public static IOpt<TResult> SelectMany<TSource, TCollection, TResult>(this IOpt<TSource> source, Func<TSource, int, IOpt<TCollection>> collectionSelector, Func<TSource, TCollection, TResult> resultSelector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Int32, IOpt<TCollection>> collectionSelector

A transform function applied to each element of source.

Func<TSource, TCollection, TResult> resultSelector

A transform function applied to each element of each intermediate option returned by collectionSelector and its corresponding element from source.

Returns
Type Description
IOpt<TResult>

A full option containing the result of applying resultSelector to the element of source and the element of the intermediate option produced by applying collectionSelector to the element of source and its index, if source is full and the intermediate option is also full; otherwise, an empty option.

Type Parameters
Name Description
TSource

The type of the elements of source.

TCollection

The type of the elements of the intermediate option produced by applying collectionSelector to an element of source and its index.

TResult

The type of the elements of the result option.

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, collectionSelector, or resultSelector is null.

| Improve this Doc View Source

SequenceEqual<TSource>(IOpt<TSource>, IEnumerable<TSource>)

Determines whether an option has an equal length and sequence of elements to a sequence.

Declaration
public static bool SequenceEqual<TSource>(this IOpt<TSource> first, IEnumerable<TSource> second)
Parameters
Type Name Description
IOpt<TSource> first

A source option.

IEnumerable<TSource> second

A sequence whose contents to compare with those of first.

Returns
Type Description
Boolean

true if first and second are both empty or each of first and second contains exactly one element and those elements are equal; otherwise, false.

Type Parameters
Name Description
TSource

The type of the elements of first and second.

Exceptions
Type Condition
ArgumentNullException

first or second is null.

| Improve this Doc View Source

SequenceEqual<TSource>(IOpt<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>)

Determines whether an option has an equal length and sequence of elements to a sequence.

Declaration
public static bool SequenceEqual<TSource>(this IOpt<TSource> first, IEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
Parameters
Type Name Description
IOpt<TSource> first

A source option.

IEnumerable<TSource> second

A sequence whose contents to compare with those of first.

IEqualityComparer<TSource> comparer

A comparer to determine whether values are equal. (If null, Default is used.)

Returns
Type Description
Boolean

true if first and second are both empty or each of first and second contains exactly one element and those elements are equal; otherwise, false.

Type Parameters
Name Description
TSource

The type of the elements of first and second.

Exceptions
Type Condition
ArgumentNullException

first or second is null.

| Improve this Doc View Source

Single<TSource>(IOpt<TSource>)

Returns the only element of an option.

Declaration
public static TSource Single<TSource>(this IOpt<TSource> source)
Parameters
Type Name Description
IOpt<TSource> source

An option to return an element from.

Returns
Type Description
TSource

The only element of source.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source is empty.

| Improve this Doc View Source

Single<TSource>(IOpt<TSource>, Func<TSource, Boolean>)

Returns the only element of an option that satisfies a condition.

Declaration
public static TSource Single<TSource>(this IOpt<TSource> source, Func<TSource, bool> predicate)
Parameters
Type Name Description
IOpt<TSource> source

An option to return an element from.

Func<TSource, Boolean> predicate

A function to test each element for a condition.

Returns
Type Description
TSource

The only element of source that satisfies predicate.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

InvalidOperationException

source does not contain any element that satisfies predicate.

| Improve this Doc View Source

SingleOrDefault<TSource>(IOpt<TSource>)

Returns the only element of an option, or the default value for the type if the option is empty.

Declaration
public static TSource SingleOrDefault<TSource>(this IOpt<TSource> source)
Parameters
Type Name Description
IOpt<TSource> source

An option to return an element from.

Returns
Type Description
TSource

The only element of source, or the default value for TSource if source is empty.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

SingleOrDefault<TSource>(IOpt<TSource>, TSource)

Returns the only element of an option, or a specified default value if the option is empty.

Declaration
public static TSource SingleOrDefault<TSource>(this IOpt<TSource> source, TSource defaultValue)
Parameters
Type Name Description
IOpt<TSource> source

An option to return an element from.

TSource defaultValue

A default value to return if source contains no elements.

Returns
Type Description
TSource

The only element of source, or defaultValue if source is empty.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

SingleOrDefault<TSource>(IOpt<TSource>, Func<TSource, Boolean>)

Returns the only element of an option that satisfies a condition, or the default value for the type if no such element is found.

Declaration
public static TSource SingleOrDefault<TSource>(this IOpt<TSource> source, Func<TSource, bool> predicate)
Parameters
Type Name Description
IOpt<TSource> source

An option to return an element from.

Func<TSource, Boolean> predicate

A function to test each element for a condition.

Returns
Type Description
TSource

The only element of source that satisfies predicate, or the default value for TSource if no such element is found.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source or predicate is null.

| Improve this Doc View Source

SingleOrDefault<TSource>(IOpt<TSource>, Func<TSource, Boolean>, TSource)

Returns the only element of an option that satisfies a condition, or a specified default value if no such element is found.

Declaration
public static TSource SingleOrDefault<TSource>(this IOpt<TSource> source, Func<TSource, bool> predicate, TSource defaultValue)
Parameters
Type Name Description
IOpt<TSource> source

An option to return an element from.

Func<TSource, Boolean> predicate

A function to test each element for a condition.

TSource defaultValue

A default value to return if source contains no elements that satisfy predicate.

Returns
Type Description
TSource

The only element of source that satisfies predicate, or defaultValue if no such element is found.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source or predicate is null.

| Improve this Doc View Source

Skip<TSource>(IOpt<TSource>, Int32)

Returns the remaining contents of an option after skipping a specified number of elements.

Declaration
public static IOpt<TSource> Skip<TSource>(this IOpt<TSource> source, int count)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Int32 count

The number of elements to skip.

Returns
Type Description
IOpt<TSource>

source, if count is less than or equal to 0; otherwise, an empty option.

Type Parameters
Name Description
TSource

The type of the elements of source.

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.

If count is zero or negative, no elements are skipped. If count is greater than or equal to the number of elements of source, all elements are skipped.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

SkipWhile<TSource>(IOpt<TSource>, Func<TSource, Boolean>)

Returns the first element of an option that does not satisfy a predicate and all following elements.

Declaration
public static IOpt<TSource> SkipWhile<TSource>(this IOpt<TSource> source, Func<TSource, bool> predicate)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Boolean> predicate

A function to test each element for a condition.

Returns
Type Description
IOpt<TSource>

An empty option, if source is empty or contains an element that satisfies predicate; otherwise, an option with the same contents as source.

Type Parameters
Name Description
TSource

The type of the elements of source.

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.

If all elements of source satisfy predicate, the result is empty.

Exceptions
Type Condition
ArgumentNullException

source or predicate is null.

| Improve this Doc View Source

SkipWhile<TSource>(IOpt<TSource>, Func<TSource, Int32, Boolean>)

Returns the first element of an option that does not satisfy a predicate and all following elements.

Declaration
public static IOpt<TSource> SkipWhile<TSource>(this IOpt<TSource> source, Func<TSource, int, bool> predicate)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Int32, Boolean> predicate

A function to test each element and its index for a condition.

Returns
Type Description
IOpt<TSource>

An empty option, if source is empty or contains an element that satisfies predicate; otherwise, an option with the same contents as source.

Type Parameters
Name Description
TSource

The type of the elements of source.

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.

If all elements of source satisfy predicate, the result is empty.

Exceptions
Type Condition
ArgumentNullException

source or predicate is null.

| Improve this Doc View Source

Sum(IOpt<Decimal>)

Computes the sum of the contents of an option.

Declaration
public static decimal Sum(this IOpt<decimal> source)
Parameters
Type Name Description
IOpt<Decimal> source

A source option.

Returns
Type Description
Decimal

The value of the only element of source, or zero if source is empty.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Sum(IOpt<Double>)

Computes the sum of the contents of an option.

Declaration
public static double Sum(this IOpt<double> source)
Parameters
Type Name Description
IOpt<Double> source

A source option.

Returns
Type Description
Double

The value of the only element of source, or zero if source is empty.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Sum(IOpt<Int32>)

Computes the sum of the contents of an option.

Declaration
public static int Sum(this IOpt<int> source)
Parameters
Type Name Description
IOpt<Int32> source

A source option.

Returns
Type Description
Int32

The value of the only element of source, or zero if source is empty.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Sum(IOpt<Int64>)

Computes the sum of the contents of an option.

Declaration
public static long Sum(this IOpt<long> source)
Parameters
Type Name Description
IOpt<Int64> source

A source option.

Returns
Type Description
Int64

The value of the only element of source, or zero if source is empty.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Sum(IOpt<Nullable<Decimal>>)

Computes the sum of the non-null contents of an option.

Declaration
public static decimal? Sum(this IOpt<decimal? > source)
Parameters
Type Name Description
IOpt<Nullable<Decimal>> source

A source option.

Returns
Type Description
Nullable<Decimal>

The value of the only element of source, or zero if source is empty or contains null.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Sum(IOpt<Nullable<Double>>)

Computes the sum of the non-null contents of an option.

Declaration
public static double? Sum(this IOpt<double? > source)
Parameters
Type Name Description
IOpt<Nullable<Double>> source

A source option.

Returns
Type Description
Nullable<Double>

The value of the only element of source, or zero if source is empty or contains null.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Sum(IOpt<Nullable<Int32>>)

Computes the sum of the non-null contents of an option.

Declaration
public static int? Sum(this IOpt<int? > source)
Parameters
Type Name Description
IOpt<Nullable<Int32>> source

A source option.

Returns
Type Description
Nullable<Int32>

The value of the only element of source, or zero if source is empty or contains null.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Sum(IOpt<Nullable<Int64>>)

Computes the sum of the non-null contents of an option.

Declaration
public static long? Sum(this IOpt<long? > source)
Parameters
Type Name Description
IOpt<Nullable<Int64>> source

A source option.

Returns
Type Description
Nullable<Int64>

The value of the only element of source, or zero if source is empty or contains null.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Sum(IOpt<Nullable<Single>>)

Computes the sum of the non-null contents of an option.

Declaration
public static float? Sum(this IOpt<float? > source)
Parameters
Type Name Description
IOpt<Nullable<Single>> source

A source option.

Returns
Type Description
Nullable<Single>

The value of the only element of source, or zero if source is empty or contains null.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Sum(IOpt<Single>)

Computes the sum of the contents of an option.

Declaration
public static float Sum(this IOpt<float> source)
Parameters
Type Name Description
IOpt<Single> source

A source option.

Returns
Type Description
Single

The value of the only element of source, or zero if source is empty.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Sum<TSource>(IOpt<TSource>, Func<TSource, Decimal>)

Computes the sum of a projection of the contents of an option.

Declaration
public static decimal Sum<TSource>(this IOpt<TSource> source, Func<TSource, decimal> selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Decimal> selector

A transform function applied to each element of source.

Returns
Type Description
Decimal

The value of the result of applying selector to the only element of source, or zero if source is empty.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Sum<TSource>(IOpt<TSource>, Func<TSource, Double>)

Computes the sum of a projection of the contents of an option.

Declaration
public static double Sum<TSource>(this IOpt<TSource> source, Func<TSource, double> selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Double> selector

A transform function applied to each element of source.

Returns
Type Description
Double

The value of the result of applying selector to the only element of source, or zero if source is empty.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Sum<TSource>(IOpt<TSource>, Func<TSource, Int32>)

Computes the sum of a projection of the contents of an option.

Declaration
public static int Sum<TSource>(this IOpt<TSource> source, Func<TSource, int> selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Int32> selector

A transform function applied to each element of source.

Returns
Type Description
Int32

The value of the result of applying selector to the only element of source, or zero if source is empty.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Sum<TSource>(IOpt<TSource>, Func<TSource, Int64>)

Computes the sum of a projection of the contents of an option.

Declaration
public static long Sum<TSource>(this IOpt<TSource> source, Func<TSource, long> selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Int64> selector

A transform function applied to each element of source.

Returns
Type Description
Int64

The value of the result of applying selector to the only element of source, or zero if source is empty.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Sum<TSource>(IOpt<TSource>, Func<TSource, Nullable<Decimal>>)

Computes the sum of the non-null elements of a projection of the contents of an option.

Declaration
public static decimal? Sum<TSource>(this IOpt<TSource> source, Func<TSource, decimal? > selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Nullable<Decimal>> selector

A transform function applied to each element of source.

Returns
Type Description
Nullable<Decimal>

The value of the result of applying selector to the only element of source, source contains a value and that result is not null; otherwise, zero.

Type Parameters
Name Description
TSource

The type of the elements of source.

| Improve this Doc View Source

Sum<TSource>(IOpt<TSource>, Func<TSource, Nullable<Double>>)

Computes the sum of the non-null elements of a projection of the contents of an option.

Declaration
public static double? Sum<TSource>(this IOpt<TSource> source, Func<TSource, double? > selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Nullable<Double>> selector

A transform function applied to each element of source.

Returns
Type Description
Nullable<Double>

The value of the result of applying selector to the only element of source, source contains a value and that result is not null; otherwise, zero.

Type Parameters
Name Description
TSource

The type of the elements of source.

| Improve this Doc View Source

Sum<TSource>(IOpt<TSource>, Func<TSource, Nullable<Int32>>)

Computes the sum of the non-null elements of a projection of the contents of an option.

Declaration
public static int? Sum<TSource>(this IOpt<TSource> source, Func<TSource, int? > selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Nullable<Int32>> selector

A transform function applied to each element of source.

Returns
Type Description
Nullable<Int32>

The value of the result of applying selector to the only element of source, source contains a value and that result is not null; otherwise, zero.

Type Parameters
Name Description
TSource

The type of the elements of source.

| Improve this Doc View Source

Sum<TSource>(IOpt<TSource>, Func<TSource, Nullable<Int64>>)

Computes the sum of the non-null elements of a projection of the contents of an option.

Declaration
public static long? Sum<TSource>(this IOpt<TSource> source, Func<TSource, long? > selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Nullable<Int64>> selector

A transform function applied to each element of source.

Returns
Type Description
Nullable<Int64>

The value of the result of applying selector to the only element of source, source contains a value and that result is not null; otherwise, zero.

Type Parameters
Name Description
TSource

The type of the elements of source.

| Improve this Doc View Source

Sum<TSource>(IOpt<TSource>, Func<TSource, Nullable<Single>>)

Computes the sum of the non-null elements of a projection of the contents of an option.

Declaration
public static float? Sum<TSource>(this IOpt<TSource> source, Func<TSource, float? > selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Nullable<Single>> selector

A transform function applied to each element of source.

Returns
Type Description
Nullable<Single>

The value of the result of applying selector to the only element of source, source contains a value and that result is not null; otherwise, zero.

Type Parameters
Name Description
TSource

The type of the elements of source.

| Improve this Doc View Source

Sum<TSource>(IOpt<TSource>, Func<TSource, Single>)

Computes the sum of a projection of the contents of an option.

Declaration
public static float Sum<TSource>(this IOpt<TSource> source, Func<TSource, float> selector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Single> selector

A transform function applied to each element of source.

Returns
Type Description
Single

The value of the result of applying selector to the only element of source, or zero if source is empty.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Take<TSource>(IOpt<TSource>, Int32)

Returns the specified number of elements from an option.

Declaration
public static IOpt<TSource> Take<TSource>(this IOpt<TSource> source, int count)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Int32 count

The number of elements to return.

Returns
Type Description
IOpt<TSource>
Type Parameters
Name Description
TSource

The type of the elements of source.

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.

If count is zero or negative, no elements are returned. If count is greater than or equal to the number of elements of source, all elements are returned.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

TakeWhile<TSource>(IOpt<TSource>, Func<TSource, Boolean>)

Returns all elements of an option before the first element that does not satisfy a predicate.

Declaration
public static IOpt<TSource> TakeWhile<TSource>(this IOpt<TSource> source, Func<TSource, bool> predicate)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Boolean> predicate

A function to test each element for a condition.

Returns
Type Description
IOpt<TSource>

An empty option, if source is empty or contains an element that does not satisfy predicate; otherwise, an option with the same contents as source.

Type Parameters
Name Description
TSource

The type of the elements of source.

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.

If no elements of source satisfy predicate, the result is empty.

Exceptions
Type Condition
ArgumentNullException

source or predicate is null.

| Improve this Doc View Source

TakeWhile<TSource>(IOpt<TSource>, Func<TSource, Int32, Boolean>)

Returns all elements of an option before the first element that does not satisfy a predicate.

Declaration
public static IOpt<TSource> TakeWhile<TSource>(this IOpt<TSource> source, Func<TSource, int, bool> predicate)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Int32, Boolean> predicate

A function to test each element and its index for a condition.

Returns
Type Description
IOpt<TSource>

An empty option, if source is empty or contains an element that does not satisfy predicate; otherwise, an option with the same contents as source.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source or predicate is null.

| Improve this Doc View Source

ThenBy<TSource, TKey>(IOpt<TSource>, Func<TSource, TKey>)

Subsequently sorts the elements of an already ordered option in ascending order.

Declaration
public static IOpt<TSource> ThenBy<TSource, TKey>(this IOpt<TSource> source, Func<TSource, TKey> keySelector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, TKey> keySelector

A function to select the key that corresponds to an element of source.

Returns
Type Description
IOpt<TSource>

source.

Type Parameters
Name Description
TSource

The type of the elements of source.

TKey

The type of the key used to compare elements.

Remarks

Since an option, by virtue of being a zero- or one-element sequence, is trivially already ordered, this method returns source unmodified (after null-checking any required parameters).

Exceptions
Type Condition
ArgumentNullException

source or keySelector is null.

| Improve this Doc View Source

ThenBy<TSource, TKey>(IOpt<TSource>, Func<TSource, TKey>, IComparer<TKey>)

Subsequently sorts the elements of an already ordered option in ascending order.

Declaration
public static IOpt<TSource> ThenBy<TSource, TKey>(this IOpt<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey> comparer)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, TKey> keySelector

A function to select the key that corresponds to an element of source.

IComparer<TKey> comparer

A comparer used to order keys. (This parameter is ignored.)

Returns
Type Description
IOpt<TSource>

source.

Type Parameters
Name Description
TSource

The type of the elements of source.

TKey

The type of the key used to compare elements.

Remarks

Since an option, by virtue of being a zero- or one-element sequence, is trivially already ordered, this method returns source unmodified (after null-checking any required parameters).

Exceptions
Type Condition
ArgumentNullException

source or keySelector is null.

| Improve this Doc View Source

ThenByDescending<TSource, TKey>(IOpt<TSource>, Func<TSource, TKey>)

Subsequently sorts the elements of an already ordered option in descending order.

Declaration
public static IOpt<TSource> ThenByDescending<TSource, TKey>(this IOpt<TSource> source, Func<TSource, TKey> keySelector)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, TKey> keySelector

A function to select the key that corresponds to an element of source.

Returns
Type Description
IOpt<TSource>

source.

Type Parameters
Name Description
TSource

The type of the elements of source.

TKey

The type of the key used to compare elements.

Remarks

Since an option, by virtue of being a zero- or one-element sequence, is trivially already ordered, this method returns source unmodified (after null-checking any required parameters).

Exceptions
Type Condition
ArgumentNullException

source or keySelector is null.

| Improve this Doc View Source

ThenByDescending<TSource, TKey>(IOpt<TSource>, Func<TSource, TKey>, IComparer<TKey>)

Subsequently sorts the elements of an already ordered option in descending order.

Declaration
public static IOpt<TSource> ThenByDescending<TSource, TKey>(this IOpt<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey> comparer)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, TKey> keySelector

A function to select the key that corresponds to an element of source.

IComparer<TKey> comparer

A comparer used to order keys. (This parameter is ignored.)

Returns
Type Description
IOpt<TSource>

source.

Type Parameters
Name Description
TSource

The type of the elements of source.

TKey

The type of the key used to compare elements.

Remarks

Since an option, by virtue of being a zero- or one-element sequence, is trivially already ordered, this method returns source unmodified (after null-checking any required parameters).

Exceptions
Type Condition
ArgumentNullException

source or keySelector is null.

| Improve this Doc View Source

ToArray<TSource>(IOpt<TSource>)

Creates a new array having the same contents as an option.

Declaration
public static TSource[] ToArray<TSource>(this IOpt<TSource> source)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Returns
Type Description
TSource[]

A new single-element array containing the element of source, if it is not empty; otherwise, a new zero-element array.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

ToFixed(IOpt)

Returns a fixed option reflecting the current state of an option.

Declaration
public static Opt<object> ToFixed(this IOpt source)
Parameters
Type Name Description
IOpt source

A source option.

Returns
Type Description
Opt<Object>

A fixed option reflecting the current state of source.

| Improve this Doc View Source

ToFixed<TSource>(IOpt<TSource>)

Returns a fixed option reflecting the current state of an option.

Declaration
public static Opt<TSource> ToFixed<TSource>(this IOpt<TSource> source)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Returns
Type Description
Opt<TSource>

A fixed option reflecting the current state of source.

Type Parameters
Name Description
TSource

The element type of source.

| Improve this Doc View Source

ToList<TSource>(IOpt<TSource>)

Creates a new list having the same contents as an option.

Declaration
public static List<TSource> ToList<TSource>(this IOpt<TSource> source)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Returns
Type Description
List<TSource>

A new single-element list containing the element of source, if it is not empty; otherwise, a new empty list.

Type Parameters
Name Description
TSource

The type of the elements of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

TryGetValue<TSource>(IOpt<TSource>, out TSource)

Gets the value contained by an option, if it exists.

Declaration
public static bool TryGetValue<TSource>(this IOpt<TSource> source, out TSource value)
Parameters
Type Name Description
IOpt<TSource> source

An option whose value to get.

TSource value

When this method returns, is set to the value contained by source, if any, or the default value of TSource, otherwise.

Returns
Type Description
Boolean

true, if source contains a value; otherwise, false.

Type Parameters
Name Description
TSource

The element type of source.

Exceptions
Type Condition
ArgumentNullException

source is null.

| Improve this Doc View Source

Where<TSource>(IOpt<TSource>, Func<TSource, Boolean>)

Filters the elements of an option to those that satisfy a predicate.

Declaration
public static IOpt<TSource> Where<TSource>(this IOpt<TSource> source, Func<TSource, bool> predicate)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Boolean> predicate

A function to test an element of source.

Returns
Type Description
IOpt<TSource>

An option containing the same element as source, if source is full and its element satisfies predicate; otherwise, an empty option.

Type Parameters
Name Description
TSource

The type of the elements of source.

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 or predicate is null.

| Improve this Doc View Source

Where<TSource>(IOpt<TSource>, Func<TSource, Int32, Boolean>)

Filters the elements of an option to those that satisfy a predicate.

Declaration
public static IOpt<TSource> Where<TSource>(this IOpt<TSource> source, Func<TSource, int, bool> predicate)
Parameters
Type Name Description
IOpt<TSource> source

A source option.

Func<TSource, Int32, Boolean> predicate

A function to test an element of source and its index.

Returns
Type Description
IOpt<TSource>

An option containing the same element as source, if source is full and its element and index satisfy predicate; otherwise, an empty option.

Type Parameters
Name Description
TSource

The type of the elements of source.

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 or predicate is null.

| Improve this Doc View Source

WhereNotNull<TSource>(IOpt<TSource>)

Filters the contents of an option to include only non- null values.

Declaration
public static IOpt<TSource> WhereNotNull<TSource>(this IOpt<TSource> source)
Parameters
Type Name Description
IOpt<TSource> source

An option to filter.

Returns
Type Description
IOpt<TSource>

An option equivalent to source, if it is full and contains a non- null value; otherwise, an empty option.

Type Parameters
Name Description
TSource

The type of the elements of source.

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.

| Improve this Doc View Source

WhereNotNullSelectValue<TSource>(IOpt<Nullable<TSource>>)

Filters the contents of an option to include only non- null values, converting the results to their non-nullable type.

Declaration
public static IOpt<TSource> WhereNotNullSelectValue<TSource>(this IOpt<TSource? > source)
    where TSource : struct
Parameters
Type Name Description
IOpt<Nullable<TSource>> source

An option to filter.

Returns
Type Description
IOpt<TSource>

An option containing the same value as source, if it is full and contains a non- null value; otherwise, an empty option.

Type Parameters
Name Description
TSource

The non-nullable basis type of the type of the elements of source.

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.

| Improve this Doc View Source

Zip<TFirst, TSecond, TResult>(IOpt<TFirst>, IEnumerable<TSecond>, Func<TFirst, TSecond, TResult>)

Produces a new option by combining the value from an option with the value from another source using the specified result selector.

Declaration
public static IOpt<TResult> Zip<TFirst, TSecond, TResult>(this IOpt<TFirst> first, IEnumerable<TSecond> second, Func<TFirst, TSecond, TResult> resultSelector)
Parameters
Type Name Description
IOpt<TFirst> first

The first source.

IEnumerable<TSecond> second

The second source.

Func<TFirst, TSecond, TResult> resultSelector

A function that specifies how to combine an element from first with the corresponding element of second.

Returns
Type Description
IOpt<TResult>

An option containing the result of calling resultSelector on the element of first and the first element of second, or an empty option if either first or second is empty.

Type Parameters
Name Description
TFirst

The type of the elements of first.

TSecond

The type of the elements of second.

TResult

The type of the elements of the result option.

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

first or second is null.

  • Improve this Doc
  • View Source
Back to top Copyright © 2018-2019 Peter S. May
Generated by DocFX