Class EnumerableExtensions
- Namespace
 - LfrlAnvil.Extensions
 
- Assembly
 - LfrlAnvil.Core.dll
 
Contains IEnumerable<T> extension methods.
public static class EnumerableExtensions
  - Inheritance
 - 
      
      EnumerableExtensions
 
- Inherited Members
 
Methods
AsNullable<T>(IEnumerable<T>)
Creates a new IEnumerable<T> instance that converts source elements to Nullable<T>.
[Pure]
public static IEnumerable<T?> AsNullable<T>(this IEnumerable<T> source) where T : struct
  Parameters
sourceIEnumerable<T>Source collection.
Returns
- IEnumerable<T?>
 New IEnumerable<T> instance.
Type Parameters
TCollection element type.
ContainsAtLeast<T>(IEnumerable<T>, int)
Checks if the provided source contains at least count number of elements.
[Pure]
public static bool ContainsAtLeast<T>(this IEnumerable<T> source, int count)
  Parameters
sourceIEnumerable<T>Source collection.
countintExpected minimum number of elements.
Returns
- bool
 true when
sourcecontains correct number of elements, otherwise false.
Type Parameters
TCollection element type.
ContainsAtMost<T>(IEnumerable<T>, int)
Checks if the provided source contains at most count number of elements.
[Pure]
public static bool ContainsAtMost<T>(this IEnumerable<T> source, int count)
  Parameters
sourceIEnumerable<T>Source collection.
countintExpected maximum number of elements.
Returns
- bool
 true when
sourcecontains correct number of elements, otherwise false.
Type Parameters
TCollection element type.
ContainsDuplicates<T>(IEnumerable<T>)
Checks whether or not the provided source contains duplicated elements,
using the Default equality comparer.
[Pure]
public static bool ContainsDuplicates<T>(this IEnumerable<T> source)
  Parameters
sourceIEnumerable<T>Source collection.
Returns
- bool
 true when
sourcecontains at least one duplicated element, otherwise false.
Type Parameters
TCollection element type.
ContainsDuplicates<T>(IEnumerable<T>, IEqualityComparer<T>)
Checks whether or not the provided source contains duplicated elements.
[Pure]
public static bool ContainsDuplicates<T>(this IEnumerable<T> source, IEqualityComparer<T> comparer)
  Parameters
sourceIEnumerable<T>Source collection.
comparerIEqualityComparer<T>Comparer to use for element equality.
Returns
- bool
 true when
sourcecontains at least one duplicated element, otherwise false.
Type Parameters
TCollection element type.
ContainsExactly<T>(IEnumerable<T>, int)
Checks if the provided source contains exactly count number of elements.
[Pure]
public static bool ContainsExactly<T>(this IEnumerable<T> source, int count)
  Parameters
sourceIEnumerable<T>Source collection.
countintExpected exact number of elements.
Returns
- bool
 true when
sourcecontains correct number of elements, otherwise false.
Type Parameters
TCollection element type.
ContainsInRange<T>(IEnumerable<T>, int, int)
Checks if the provided source contains between
minCount and maxCount number of elements.
[Pure]
public static bool ContainsInRange<T>(this IEnumerable<T> source, int minCount, int maxCount)
  Parameters
sourceIEnumerable<T>Source collection.
minCountintExpected minimum number of elements.
maxCountintExpected maximum number of elements.
Returns
- bool
 true when
sourcecontains correct number of elements, otherwise false.
Type Parameters
TCollection element type.
ContainsNull<T>(IEnumerable<T?>)
Checks whether or not the provided source contains at least one null element.
[Pure]
public static bool ContainsNull<T>(this IEnumerable<T?> source) where T : struct
  Parameters
sourceIEnumerable<T?>Source collection.
Returns
- bool
 true when
sourcecontains at least one null element, otherwise false.
Type Parameters
TCollection element type.
ContainsNull<T>(IEnumerable<T?>)
Checks whether or not the provided source contains at least one null element.
[Pure]
public static bool ContainsNull<T>(this IEnumerable<T?> source) where T : class
  Parameters
sourceIEnumerable<T>Source collection.
Returns
- bool
 true when
sourcecontains at least one null element, otherwise false.
Type Parameters
TCollection element type.
ContainsNull<T>(IEnumerable<T>, IEqualityComparer<T>)
Checks whether or not the provided source contains at least one null element.
[Pure]
public static bool ContainsNull<T>(this IEnumerable<T> source, IEqualityComparer<T> comparer)
  Parameters
sourceIEnumerable<T>Source collection.
comparerIEqualityComparer<T>Element equality comparer.
Returns
- bool
 true when
sourcecontains at least one null element, otherwise false.
Type Parameters
TCollection element type.
EmptyIfNull<T>(IEnumerable<T>?)
Returns the provided source, unless it is null, in which case returns an empty enumerable instead.
[Pure]
public static IEnumerable<T> EmptyIfNull<T>(this IEnumerable<T>? source)
  Parameters
sourceIEnumerable<T>Source collection.
Returns
- IEnumerable<T>
 sourceif it is not null, otherwise an empty enumerable.
Type Parameters
TCollection element type.
Flatten<T>(IEnumerable<IEnumerable<T>>)
Creates a new IEnumerable<T> instance that contains all elements from nested collections.
[Pure]
public static IEnumerable<T> Flatten<T>(this IEnumerable<IEnumerable<T>> source)
  Parameters
sourceIEnumerable<IEnumerable<T>>Source collection.
Returns
- IEnumerable<T>
 
Type Parameters
TCollection element type.
Flatten<T1, T2>(IEnumerable<T1>, Func<T1, IEnumerable<T2>>)
Creates a new IEnumerable<T> instance that contains a collection of (parent, child) pairs.
[Pure]
public static IEnumerable<Pair<T1, T2>> Flatten<T1, T2>(this IEnumerable<T1> source, Func<T1, IEnumerable<T2>> selector)
  Parameters
sourceIEnumerable<T1>Source collection.
selectorFunc<T1, IEnumerable<T2>>Child selector.
Returns
- IEnumerable<Pair<T1, T2>>
 New IEnumerable<T> instance.
Type Parameters
T1Source collection element (parent) type.
T2Child type.
Flatten<T1, T2, TResult>(IEnumerable<T1>, Func<T1, IEnumerable<T2>>, Func<T1, T2, TResult>)
Creates a new IEnumerable<T> instance that contains a collection of (parent, child) pairs mapped to the desired type.
[Pure]
public static IEnumerable<TResult> Flatten<T1, T2, TResult>(this IEnumerable<T1> source, Func<T1, IEnumerable<T2>> selector, Func<T1, T2, TResult> resultMapper)
  Parameters
sourceIEnumerable<T1>Source collection.
selectorFunc<T1, IEnumerable<T2>>Child selector.
resultMapperFunc<T1, T2, TResult>Result selector.
Returns
- IEnumerable<TResult>
 New IEnumerable<T> instance.
Type Parameters
T1Source collection element (parent) type.
T2Child type.
TResultResult type.
FullJoin<T1, T2, TKey, TResult>(IEnumerable<T1>, IEnumerable<T2>, Func<T1, TKey>, Func<T2, TKey>, Func<T1?, T2?, TResult>)
Return a new IEnumerable<T> that contains the result of performing full outer join on two collections by using the Default key equality comparer.
[Pure]
public static IEnumerable<TResult> FullJoin<T1, T2, TKey, TResult>(this IEnumerable<T1> outer, IEnumerable<T2> inner, Func<T1, TKey> outerKeySelector, Func<T2, TKey> innerKeySelector, Func<T1?, T2?, TResult> resultSelector)
  Parameters
outerIEnumerable<T1>Outer collection.
innerIEnumerable<T2>Inner collection.
outerKeySelectorFunc<T1, TKey>Selector of outer collection element keys.
innerKeySelectorFunc<T2, TKey>Selector of inner collection element keys.
resultSelectorFunc<T1, T2, TResult>Joined elements result selector.
Returns
- IEnumerable<TResult>
 New IEnumerable<T> instance.
Type Parameters
T1Outer collection element type.
T2Inner collection element type.
TKeyKey type.
TResultResult type.
FullJoin<T1, T2, TKey, TResult>(IEnumerable<T1>, IEnumerable<T2>, Func<T1, TKey>, Func<T2, TKey>, Func<T1?, T2?, TResult>, IEqualityComparer<TKey>)
Return a new IEnumerable<T> that contains the result of performing full outer join on two collections.
[Pure]
public static IEnumerable<TResult> FullJoin<T1, T2, TKey, TResult>(this IEnumerable<T1> outer, IEnumerable<T2> inner, Func<T1, TKey> outerKeySelector, Func<T2, TKey> innerKeySelector, Func<T1?, T2?, TResult> resultSelector, IEqualityComparer<TKey> keyComparer)
  Parameters
outerIEnumerable<T1>Outer collection.
innerIEnumerable<T2>Inner collection.
outerKeySelectorFunc<T1, TKey>Selector of outer collection element keys.
innerKeySelectorFunc<T2, TKey>Selector of inner collection element keys.
resultSelectorFunc<T1, T2, TResult>Joined elements result selector.
keyComparerIEqualityComparer<TKey>Comparer to use for key equality comparison.
Returns
- IEnumerable<TResult>
 New IEnumerable<T> instance.
Type Parameters
T1Outer collection element type.
T2Inner collection element type.
TKeyKey type.
TResultResult type.
IsEmpty<T>(IEnumerable<T>)
Checks if the provided source is empty.
[Pure]
public static bool IsEmpty<T>(this IEnumerable<T> source)
  Parameters
sourceIEnumerable<T>Source collection.
Returns
- bool
 true when
sourceis empty, otherwise false.
Type Parameters
TCollection element type.
IsMaterialized<T>(IEnumerable<T>)
Checks whether or not the provided source is either an instance of IReadOnlyCollection<T>
or of IMemoizedCollection<T> with IsMaterialized set to true.
[Pure]
public static bool IsMaterialized<T>(this IEnumerable<T> source)
  Parameters
sourceIEnumerable<T>Source collection.
Returns
- bool
 true when
sourceis considered to be materialized, otherwise false.
Type Parameters
TCollection element type.
IsMemoized<T>(IEnumerable<T>)
Checks whether or not the provided source is an instance of IMemoizedCollection<T>.
[Pure]
public static bool IsMemoized<T>(this IEnumerable<T> source)
  Parameters
sourceIEnumerable<T>Source collection.
Returns
- bool
 true when
sourceis considered to be memoized, otherwise false.
Type Parameters
TCollection element type.
IsNullOrEmpty<T>(IEnumerable<T>?)
Checks if the provided source is null or empty.
[Pure]
public static bool IsNullOrEmpty<T>(this IEnumerable<T>? source)
  Parameters
sourceIEnumerable<T>Source collection.
Returns
- bool
 true when
sourceis null or empty, otherwise false.
Type Parameters
TCollection element type.
IsOrdered<T>(IEnumerable<T>)
Checks whether or not the provided source elements are ordered
by using the Default comparer.
[Pure]
public static bool IsOrdered<T>(this IEnumerable<T> source)
  Parameters
sourceIEnumerable<T>Source collection.
Returns
- bool
 true when
sourceis ordered, otherwise false.
Type Parameters
TCollection element type.
IsOrdered<T>(IEnumerable<T>, IComparer<T>)
Checks whether or not the provided source elements are ordered.
[Pure]
public static bool IsOrdered<T>(this IEnumerable<T> source, IComparer<T> comparer)
  Parameters
sourceIEnumerable<T>Source collection.
comparerIComparer<T>Comparer to use for value comparison.
Returns
- bool
 true when
sourceis ordered, otherwise false.
Type Parameters
TCollection element type.
LeftJoin<T1, T2, TKey, TResult>(IEnumerable<T1>, IEnumerable<T2>, Func<T1, TKey>, Func<T2, TKey>, Func<T1, T2?, TResult>)
Return a new IEnumerable<T> that contains the result of performing left outer join on two collections by using the Default key equality comparer.
[Pure]
public static IEnumerable<TResult> LeftJoin<T1, T2, TKey, TResult>(this IEnumerable<T1> outer, IEnumerable<T2> inner, Func<T1, TKey> outerKeySelector, Func<T2, TKey> innerKeySelector, Func<T1, T2?, TResult> resultSelector)
  Parameters
outerIEnumerable<T1>Outer collection.
innerIEnumerable<T2>Inner collection.
outerKeySelectorFunc<T1, TKey>Selector of outer collection element keys.
innerKeySelectorFunc<T2, TKey>Selector of inner collection element keys.
resultSelectorFunc<T1, T2, TResult>Joined elements result selector.
Returns
- IEnumerable<TResult>
 New IEnumerable<T> instance.
Type Parameters
T1Outer collection element type.
T2Inner collection element type.
TKeyKey type.
TResultResult type.
LeftJoin<T1, T2, TKey, TResult>(IEnumerable<T1>, IEnumerable<T2>, Func<T1, TKey>, Func<T2, TKey>, Func<T1, T2?, TResult>, IEqualityComparer<TKey>)
Return a new IEnumerable<T> that contains the result of performing left outer join on two collections.
[Pure]
public static IEnumerable<TResult> LeftJoin<T1, T2, TKey, TResult>(this IEnumerable<T1> outer, IEnumerable<T2> inner, Func<T1, TKey> outerKeySelector, Func<T2, TKey> innerKeySelector, Func<T1, T2?, TResult> resultSelector, IEqualityComparer<TKey> keyComparer)
  Parameters
outerIEnumerable<T1>Outer collection.
innerIEnumerable<T2>Inner collection.
outerKeySelectorFunc<T1, TKey>Selector of outer collection element keys.
innerKeySelectorFunc<T2, TKey>Selector of inner collection element keys.
resultSelectorFunc<T1, T2, TResult>Joined elements result selector.
keyComparerIEqualityComparer<TKey>Comparer to use for key equality comparison.
Returns
- IEnumerable<TResult>
 New IEnumerable<T> instance.
Type Parameters
T1Outer collection element type.
T2Inner collection element type.
TKeyKey type.
TResultResult type.
Materialize<T>(IEnumerable<T>)
Materialized the provided source.
[Pure]
public static IReadOnlyCollection<T> Materialize<T>(this IEnumerable<T> source)
  Parameters
sourceIEnumerable<T>Source collection.
Returns
- IReadOnlyCollection<T>
 New IEnumerable<T> instance, or
sourcewhen it is an instance of IReadOnlyCollection<T>, or memoized value whensourceis an instance of IMemoizedCollection<T>.
Type Parameters
TCollection element type.
Memoize<T>(IEnumerable<T>)
Memoizes the provided source.
[Pure]
public static IMemoizedCollection<T> Memoize<T>(this IEnumerable<T> source)
  Parameters
sourceIEnumerable<T>Source collection.
Returns
- IMemoizedCollection<T>
 New IMemoizedCollection<T> instance, or
sourcewhen it is an instance of IMemoizedCollection<T>.
Type Parameters
TCollection element type.
MinMaxBy<T1, T2>(IEnumerable<T1>, Func<T1, T2>)
Finds elements with minimum and maximum values specified by the selector
in the provided source by using the Default comparer.
[Pure]
public static (T1 Min, T1 Max) MinMaxBy<T1, T2>(this IEnumerable<T1> source, Func<T1, T2> selector)
  Parameters
sourceIEnumerable<T1>Source collection.
selectorFunc<T1, T2>Selector of a value to use for comparison.
Returns
Type Parameters
T1Collection element type.
T2Value type used for comparison.
Exceptions
- InvalidOperationException
 When
sourceis empty.
MinMaxBy<T1, T2>(IEnumerable<T1>, Func<T1, T2>, IComparer<T2>)
Finds elements with minimum and maximum values specified by the selector
in the provided source.
[Pure]
public static (T1 Min, T1 Max) MinMaxBy<T1, T2>(this IEnumerable<T1> source, Func<T1, T2> selector, IComparer<T2> comparer)
  Parameters
sourceIEnumerable<T1>Source collection.
selectorFunc<T1, T2>Selector of a value to use for comparison.
comparerIComparer<T2>Comparer to use for value comparison.
Returns
Type Parameters
T1Collection element type.
T2Value type used for comparison.
Exceptions
- InvalidOperationException
 When
sourceis empty.
MinMaxBy<T1, T2, T3>(IEnumerable<T1>, Func<T1, T2>, Func<T1, T3>)
Finds elements with minimum and maximum values specified by minSelector and maxSelector
in the provided source by using the Default comparer.
[Pure]
public static (T1 Min, T1 Max) MinMaxBy<T1, T2, T3>(this IEnumerable<T1> source, Func<T1, T2> minSelector, Func<T1, T3> maxSelector)
  Parameters
sourceIEnumerable<T1>Source collection.
minSelectorFunc<T1, T2>Selector of a minimum value to use for comparison.
maxSelectorFunc<T1, T3>Selector of a maximum value to use for comparison.
Returns
Type Parameters
T1Collection element type.
T2Type used for minimum value comparison.
T3Type used for maximum value comparison.
Exceptions
- InvalidOperationException
 When
sourceis empty.
MinMaxBy<T1, T2, T3>(IEnumerable<T1>, Func<T1, T2>, Func<T1, T3>, IComparer<T2>, IComparer<T3>)
Finds elements with minimum and maximum values specified by minSelector and maxSelector
in the provided source.
[Pure]
public static (T1 Min, T1 Max) MinMaxBy<T1, T2, T3>(this IEnumerable<T1> source, Func<T1, T2> minSelector, Func<T1, T3> maxSelector, IComparer<T2> minComparer, IComparer<T3> maxComparer)
  Parameters
sourceIEnumerable<T1>Source collection.
minSelectorFunc<T1, T2>Selector of a minimum value to use for comparison.
maxSelectorFunc<T1, T3>Selector of a maximum value to use for comparison.
minComparerIComparer<T2>Comparer to use for minimum value comparison.
maxComparerIComparer<T3>Comparer to use for maximum value comparison.
Returns
Type Parameters
T1Collection element type.
T2Type used for minimum value comparison.
T3Type used for maximum value comparison.
Exceptions
- InvalidOperationException
 When
sourceis empty.
MinMax<T>(IEnumerable<T>)
Finds the minimum and maximum value in the provided source
by using the Default comparer.
[Pure]
public static (T Min, T Max) MinMax<T>(this IEnumerable<T> source)
  Parameters
sourceIEnumerable<T>Source collection.
Returns
Type Parameters
TCollection element type.
Exceptions
- InvalidOperationException
 When
sourceis empty.
MinMax<T>(IEnumerable<T>, IComparer<T>)
Finds the minimum and maximum value in the provided source.
[Pure]
public static (T Min, T Max) MinMax<T>(this IEnumerable<T> source, IComparer<T> comparer)
  Parameters
sourceIEnumerable<T>Source collection.
comparerIComparer<T>Comparer to use for element comparison.
Returns
Type Parameters
TCollection element type.
Exceptions
- InvalidOperationException
 When
sourceis empty.
Partition<T>(IEnumerable<T>, Func<T, bool>)
Partitions the provided source into two groups:
elements that pass the specified predicate and elements that fail.
[Pure]
public static PartitionResult<T> Partition<T>(this IEnumerable<T> source, Func<T, bool> predicate)
  Parameters
sourceIEnumerable<T>Source collection.
predicateFunc<T, bool>Predicate to use for collection partitioning.
Returns
- PartitionResult<T>
 New PartitionResult<T> instance.
Type Parameters
TCollection element type.
Remarks
Partitioning creates a new materialized collection.
Repeat<T>(IEnumerable<T>, int)
Creates a new IEnumerable<T> instance that contains the source
repeated count times.
[Pure]
public static IEnumerable<T> Repeat<T>(this IEnumerable<T> source, int count)
  Parameters
sourceIEnumerable<T>Source collection.
countintNumber of
sourcerepetitions.
Returns
- IEnumerable<T>
 New IEnumerable<T> instance, or empty enumerable when
countis equal to 0, orsourcewhencountis equal to 1 .
Type Parameters
TCollection element type.
Exceptions
- ArgumentOutOfRangeException
 When
countis less than 0.
SetEquals<T>(IEnumerable<T>, IEnumerable<T>)
Checks whether or not the two collections are considered to be equal sets, using the Default equality comparer.
[Pure]
public static bool SetEquals<T>(this IEnumerable<T> source, IEnumerable<T> other)
  Parameters
sourceIEnumerable<T>First collection.
otherIEnumerable<T>Second collection.
Returns
- bool
 true when the two collections are equivalent sets, otherwise false.
Type Parameters
TElement type.
SetEquals<T>(IEnumerable<T>, IEnumerable<T>, IEqualityComparer<T>)
Checks whether or not the two collections are considered to be equal sets.
[Pure]
public static bool SetEquals<T>(this IEnumerable<T> source, IEnumerable<T> other, IEqualityComparer<T> comparer)
  Parameters
sourceIEnumerable<T>First collection.
otherIEnumerable<T>Second collection.
comparerIEqualityComparer<T>Comparer to use for element comparison.
Returns
- bool
 true when the two collections are equivalent sets, otherwise false.
Type Parameters
TElement type.
Slice<T>(IEnumerable<T>, int, int)
Creates a new IEnumerable<T> instance that represents a slice, or a sub-range, of source elements.
[Pure]
public static IEnumerable<T> Slice<T>(this IEnumerable<T> source, int startIndex, int length)
  Parameters
sourceIEnumerable<T>Source collection.
startIndexintIndex of the first element to include in the slice.
lengthintLength of the slice.
Returns
- IEnumerable<T>
 New IEnumerable<T> instance, or an empty enumerable when
lengthis less than 1 or when computed index of the last slice element is less than 1.
Type Parameters
TCollection element type.
ToMemory<T>(IEnumerable<T>)
Converts provided source to ReadOnlyMemory<T> instance.
[Pure]
public static ReadOnlyMemory<T> ToMemory<T>(this IEnumerable<T> source)
  Parameters
sourceIEnumerable<T>Source collection.
Returns
- ReadOnlyMemory<T>
 New ReadOnlyMemory<T> instance.
Type Parameters
TCollection element type.
Remarks
New array will not be allocated when the provided source itself is an array
or a string or an enumerable whose count can be cheaply extracted and it is empty.
TryAggregate<T>(IEnumerable<T>, Func<T, T, T>, out T)
Attempts to compute an aggregation for the provided source.
public static bool TryAggregate<T>(this IEnumerable<T> source, Func<T, T, T> func, out T result)
  Parameters
sourceIEnumerable<T>Source collection.
funcFunc<T, T, T>Aggregator delegate.
resultTout parameter that contains aggregation result, when
sourceis not empty.
Returns
- bool
 true when
sourceis not empty, otherwise false.
Type Parameters
TCollection element type.
TryMaxBy<T1, T2>(IEnumerable<T1>, Func<T1, T2>, IComparer<T2>, out T1)
Attempts to find an element with the maximum value specified by the selector
in the provided source.
public static bool TryMaxBy<T1, T2>(this IEnumerable<T1> source, Func<T1, T2> selector, IComparer<T2> comparer, out T1 result)
  Parameters
sourceIEnumerable<T1>Source collection.
selectorFunc<T1, T2>Selector of a value to use for comparison.
comparerIComparer<T2>Comparer to use for value comparison.
resultT1out parameter that contains the element with maximum value, if the collection is not empty.
Returns
- bool
 true when
sourceis not empty, otherwise false.
Type Parameters
T1Collection element type.
T2Value type used for comparison.
TryMaxBy<T1, T2>(IEnumerable<T1>, Func<T1, T2>, out T1)
Attempts to find an element with the maximum value specified by the selector
in the provided source using the Default comparer.
public static bool TryMaxBy<T1, T2>(this IEnumerable<T1> source, Func<T1, T2> selector, out T1 result)
  Parameters
sourceIEnumerable<T1>Source collection.
selectorFunc<T1, T2>Selector of a value to use for comparison.
resultT1out parameter that contains the element with maximum value, if the collection is not empty.
Returns
- bool
 true when
sourceis not empty, otherwise false.
Type Parameters
T1Collection element type.
T2Value type used for comparison.
TryMax<T>(IEnumerable<T>, IComparer<T>, out T)
Attempts to find the maximum value in the provided source.
public static bool TryMax<T>(this IEnumerable<T> source, IComparer<T> comparer, out T result)
  Parameters
sourceIEnumerable<T>Source collection.
comparerIComparer<T>Comparer to use for element comparison.
resultTout parameter that contains the maximum value, if the collection is not empty.
Returns
- bool
 true when
sourceis not empty, otherwise false.
Type Parameters
TCollection element type.
TryMax<T>(IEnumerable<T>, out T)
Attempts to find the maximum value in the provided source
by using the Default comparer.
public static bool TryMax<T>(this IEnumerable<T> source, out T result)
  Parameters
sourceIEnumerable<T>Source collection.
resultTout parameter that contains the maximum value, if the collection is not empty.
Returns
- bool
 true when
sourceis not empty, otherwise false.
Type Parameters
TCollection element type.
TryMinBy<T1, T2>(IEnumerable<T1>, Func<T1, T2>, IComparer<T2>, out T1)
Attempts to find an element with the minimum value specified by the selector
in the provided source.
public static bool TryMinBy<T1, T2>(this IEnumerable<T1> source, Func<T1, T2> selector, IComparer<T2> comparer, out T1 result)
  Parameters
sourceIEnumerable<T1>Source collection.
selectorFunc<T1, T2>Selector of a value to use for comparison.
comparerIComparer<T2>Comparer to use for value comparison.
resultT1out parameter that contains the element with minimum value, if the collection is not empty.
Returns
- bool
 true when
sourceis not empty, otherwise false.
Type Parameters
T1Collection element type.
T2Value type used for comparison.
TryMinBy<T1, T2>(IEnumerable<T1>, Func<T1, T2>, out T1)
Attempts to find an element with the minimum value specified by the selector
in the provided source using the Default comparer.
public static bool TryMinBy<T1, T2>(this IEnumerable<T1> source, Func<T1, T2> selector, out T1 result)
  Parameters
sourceIEnumerable<T1>Source collection.
selectorFunc<T1, T2>Selector of a value to use for comparison.
resultT1out parameter that contains the element with minimum value, if the collection is not empty.
Returns
- bool
 true when
sourceis not empty, otherwise false.
Type Parameters
T1Collection element type.
T2Value type used for comparison.
TryMinMaxBy<T1, T2>(IEnumerable<T1>, Func<T1, T2>)
Attempts to find elements with minimum and maximum values specified by the selector
in the provided source using the Default comparer.
[Pure]
public static (T1 Min, T1 Max)? TryMinMaxBy<T1, T2>(this IEnumerable<T1> source, Func<T1, T2> selector)
  Parameters
sourceIEnumerable<T1>Source collection.
selectorFunc<T1, T2>Selector of a value to use for comparison.
Returns
- (T1 Min, T1 Max)?
 A tuple containing elements with Min and Max values, or null when
sourceis empty.
Type Parameters
T1Collection element type.
T2Value type used for comparison.
TryMinMaxBy<T1, T2>(IEnumerable<T1>, Func<T1, T2>, IComparer<T2>)
Attempts to find elements with minimum and maximum values specified by the selector
in the provided source.
[Pure]
public static (T1 Min, T1 Max)? TryMinMaxBy<T1, T2>(this IEnumerable<T1> source, Func<T1, T2> selector, IComparer<T2> comparer)
  Parameters
sourceIEnumerable<T1>Source collection.
selectorFunc<T1, T2>Selector of a value to use for comparison.
comparerIComparer<T2>Comparer to use for value comparison.
Returns
- (T1 Min, T1 Max)?
 A tuple containing elements with Min and Max values, or null when
sourceis empty.
Type Parameters
T1Collection element type.
T2Value type used for comparison.
TryMinMaxBy<T1, T2, T3>(IEnumerable<T1>, Func<T1, T2>, Func<T1, T3>)
Attempts to find elements with minimum and maximum values specified by minSelector
and maxSelector in the provided source using the Default comparer.
[Pure]
public static (T1 Min, T1 Max)? TryMinMaxBy<T1, T2, T3>(this IEnumerable<T1> source, Func<T1, T2> minSelector, Func<T1, T3> maxSelector)
  Parameters
sourceIEnumerable<T1>Source collection.
minSelectorFunc<T1, T2>Selector of a minimum value to use for comparison.
maxSelectorFunc<T1, T3>Selector of a maximum value to use for comparison.
Returns
- (T1 Min, T1 Max)?
 A tuple containing elements with Min and Max values, or null when
sourceis empty.
Type Parameters
T1Collection element type.
T2Type used for minimum value comparison.
T3Type used for maximum value comparison.
TryMinMaxBy<T1, T2, T3>(IEnumerable<T1>, Func<T1, T2>, Func<T1, T3>, IComparer<T2>, IComparer<T3>)
Attempts to find elements with minimum and maximum values specified by minSelector
and maxSelector in the provided source.
[Pure]
public static (T1 Min, T1 Max)? TryMinMaxBy<T1, T2, T3>(this IEnumerable<T1> source, Func<T1, T2> minSelector, Func<T1, T3> maxSelector, IComparer<T2> minComparer, IComparer<T3> maxComparer)
  Parameters
sourceIEnumerable<T1>Source collection.
minSelectorFunc<T1, T2>Selector of a minimum value to use for comparison.
maxSelectorFunc<T1, T3>Selector of a maximum value to use for comparison.
minComparerIComparer<T2>Comparer to use for minimum value comparison.
maxComparerIComparer<T3>Comparer to use for maximum value comparison.
Returns
- (T1 Min, T1 Max)?
 A tuple containing elements with Min and Max values, or null when
sourceis empty.
Type Parameters
T1Collection element type.
T2Type used for minimum value comparison.
T3Type used for maximum value comparison.
TryMinMax<T>(IEnumerable<T>)
Attempts to find the minimum and maximum value in the provided source
by using the Default comparer.
[Pure]
public static (T Min, T Max)? TryMinMax<T>(this IEnumerable<T> source)
  Parameters
sourceIEnumerable<T>Source collection.
Returns
Type Parameters
TCollection element type.
TryMinMax<T>(IEnumerable<T>, IComparer<T>)
Attempts to find the minimum and maximum value in the provided source.
[Pure]
public static (T Min, T Max)? TryMinMax<T>(this IEnumerable<T> source, IComparer<T> comparer)
  Parameters
sourceIEnumerable<T>Source collection.
comparerIComparer<T>Comparer to use for element comparison.
Returns
Type Parameters
TCollection element type.
TryMin<T>(IEnumerable<T>, IComparer<T>, out T)
Attempts to find the minimum value in the provided source.
public static bool TryMin<T>(this IEnumerable<T> source, IComparer<T> comparer, out T result)
  Parameters
sourceIEnumerable<T>Source collection.
comparerIComparer<T>Comparer to use for element comparison.
resultTout parameter that contains the minimum value, if the collection is not empty.
Returns
- bool
 true when
sourceis not empty, otherwise false.
Type Parameters
TCollection element type.
TryMin<T>(IEnumerable<T>, out T)
Attempts to find the minimum value in the provided source
by using the Default comparer.
public static bool TryMin<T>(this IEnumerable<T> source, out T result)
  Parameters
sourceIEnumerable<T>Source collection.
resultTout parameter that contains the minimum value, if the collection is not empty.
Returns
- bool
 true when
sourceis not empty, otherwise false.
Type Parameters
TCollection element type.
VisitMany<T>(IEnumerable<T>, Func<T, IEnumerable<T>>)
Recursively visits an object graph, where next objects to visit are calculated by
invoking the specified nodeRangeSelector with current object as its parameter,
starting with the given source collection.
[Pure]
public static IEnumerable<T> VisitMany<T>(this IEnumerable<T> source, Func<T, IEnumerable<T>> nodeRangeSelector)
  Parameters
sourceIEnumerable<T>Source collection.
nodeRangeSelectorFunc<T, IEnumerable<T>>Descendant node range selector.
Returns
- IEnumerable<T>
 New IEnumerable<T> instance that contains all recursively visited objects, in order of traversal.
Type Parameters
TCollection element type.
Remarks
Objects are traversed in breadth-first order.
VisitMany<T>(IEnumerable<T>, Func<T, IEnumerable<T>>, Func<T, bool>)
Recursively visits an object graph, where next objects to visit are calculated by
invoking the specified nodeRangeSelector with current object as its parameter,
starting with the given source collection.
[Pure]
public static IEnumerable<T> VisitMany<T>(this IEnumerable<T> source, Func<T, IEnumerable<T>> nodeRangeSelector, Func<T, bool> stopPredicate)
  Parameters
sourceIEnumerable<T>Source collection.
nodeRangeSelectorFunc<T, IEnumerable<T>>Descendant node range selector.
stopPredicateFunc<T, bool>Predicate that stops the traversal for the given sub-graph, when it returns true.
Returns
- IEnumerable<T>
 New IEnumerable<T> instance that contains all recursively visited objects, in order of traversal.
Type Parameters
TCollection element type.
Remarks
Objects are traversed in breadth-first order.
WhereNotNull<T>(IEnumerable<T?>)
Filters out null elements from the provided source.
[Pure]
public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> source) where T : struct
  Parameters
sourceIEnumerable<T?>Source collection.
Returns
- IEnumerable<T>
 New IEnumerable<T> with null elements filtered out.
Type Parameters
TCollection element type.
WhereNotNull<T>(IEnumerable<T?>)
Filters out null elements from the provided source.
[Pure]
public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> source) where T : class
  Parameters
sourceIEnumerable<T>Source collection.
Returns
- IEnumerable<T>
 New IEnumerable<T> with null elements filtered out.
Type Parameters
TCollection element type.
WhereNotNull<T>(IEnumerable<T?>, IEqualityComparer<T>)
Filters out null elements from the provided source.
[Pure]
public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> source, IEqualityComparer<T> comparer)
  Parameters
sourceIEnumerable<T>Source collection.
comparerIEqualityComparer<T>Element equality comparer.
Returns
- IEnumerable<T>
 New IEnumerable<T> with null elements filtered out, or
sourcewhen element type is a non-nullable value type.
Type Parameters
TCollection element type.