Table of Contents

Method MinOrNone

Namespace
SodaFlow.Functional
Assembly
SodaFlow.Functional.dll

MinOrNone<T>(IEnumerable<T>?)

Returns the smallest element of a sequence, if it has any.

[Pure]
public static Maybe<T> MinOrNone<T>(this IEnumerable<T>? source)

Parameters

source IEnumerable<T>

The sequence to search. A null sequence counts as empty.

Returns

Maybe<T>

A Maybe<T> containing the smallest element by Default, and no value if there is nothing to compare.

Type Parameters

T

The type of the values in the sequence.

Remarks

Min<TSource>(IEnumerable<TSource>) throws on an empty sequence of a non-nullable type. On one of a nullable type it gives null, which is the same answer as a sequence whose smallest element is null. The two are not good answers, and the two are not necessary after the result can say there was nothing to compare.

MinOrNone<T>(IEnumerable<T>?, IComparer<T>?)

Returns the smallest element of a sequence by the given comparer, if it has any.

[Pure]
public static Maybe<T> MinOrNone<T>(this IEnumerable<T>? source, IComparer<T>? comparer)

Parameters

source IEnumerable<T>

The sequence to search. A null sequence counts as empty.

comparer IComparer<T>

The ordering to use. null means Default.

Returns

Maybe<T>

A Maybe<T> containing the smallest element, and no value if there is nothing to compare.

Type Parameters

T

The type of the values in the sequence.

MinOrNone<T, TResult>(IEnumerable<T>?, Func<T, TResult>)

Returns the smallest value produced from a sequence, if it has any elements.

[Pure]
public static Maybe<TResult> MinOrNone<T, TResult>(this IEnumerable<T>? source, Func<T, TResult> selector)

Parameters

source IEnumerable<T>

The sequence to search. A null sequence counts as empty.

selector Func<T, TResult>

Applied to each element to give the value to compare.

Returns

Maybe<TResult>

A Maybe<T> containing the smallest produced value by Default, and no value if there is nothing to compare.

Type Parameters

T

The type of the values in the sequence.

TResult

The type of the values to compare.

Remarks

This returns the smallest value selector produced, not the element which gave it. For the element, order by the key and use FirstOrNone<T>(IEnumerable<T>?).