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
source
IEnumerable<T>Source collection.
Returns
- IEnumerable<T?>
New IEnumerable<T> instance.
Type Parameters
T
Collection 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
source
IEnumerable<T>Source collection.
count
intExpected minimum number of elements.
Returns
- bool
true when
source
contains correct number of elements, otherwise false.
Type Parameters
T
Collection 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
source
IEnumerable<T>Source collection.
count
intExpected maximum number of elements.
Returns
- bool
true when
source
contains correct number of elements, otherwise false.
Type Parameters
T
Collection 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
source
IEnumerable<T>Source collection.
Returns
- bool
true when
source
contains at least one duplicated element, otherwise false.
Type Parameters
T
Collection 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
source
IEnumerable<T>Source collection.
comparer
IEqualityComparer<T>Comparer to use for element equality.
Returns
- bool
true when
source
contains at least one duplicated element, otherwise false.
Type Parameters
T
Collection 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
source
IEnumerable<T>Source collection.
count
intExpected exact number of elements.
Returns
- bool
true when
source
contains correct number of elements, otherwise false.
Type Parameters
T
Collection 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
source
IEnumerable<T>Source collection.
minCount
intExpected minimum number of elements.
maxCount
intExpected maximum number of elements.
Returns
- bool
true when
source
contains correct number of elements, otherwise false.
Type Parameters
T
Collection 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
source
IEnumerable<T?>Source collection.
Returns
- bool
true when
source
contains at least one null element, otherwise false.
Type Parameters
T
Collection 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
source
IEnumerable<T>Source collection.
Returns
- bool
true when
source
contains at least one null element, otherwise false.
Type Parameters
T
Collection 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
source
IEnumerable<T>Source collection.
comparer
IEqualityComparer<T>Element equality comparer.
Returns
- bool
true when
source
contains at least one null element, otherwise false.
Type Parameters
T
Collection 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
source
IEnumerable<T>Source collection.
Returns
- IEnumerable<T>
source
if it is not null, otherwise an empty enumerable.
Type Parameters
T
Collection 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
source
IEnumerable<IEnumerable<T>>Source collection.
Returns
- IEnumerable<T>
Type Parameters
T
Collection 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
source
IEnumerable<T1>Source collection.
selector
Func<T1, IEnumerable<T2>>Child selector.
Returns
- IEnumerable<Pair<T1, T2>>
New IEnumerable<T> instance.
Type Parameters
T1
Source collection element (parent) type.
T2
Child 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
source
IEnumerable<T1>Source collection.
selector
Func<T1, IEnumerable<T2>>Child selector.
resultMapper
Func<T1, T2, TResult>Result selector.
Returns
- IEnumerable<TResult>
New IEnumerable<T> instance.
Type Parameters
T1
Source collection element (parent) type.
T2
Child type.
TResult
Result 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
outer
IEnumerable<T1>Outer collection.
inner
IEnumerable<T2>Inner collection.
outerKeySelector
Func<T1, TKey>Selector of outer collection element keys.
innerKeySelector
Func<T2, TKey>Selector of inner collection element keys.
resultSelector
Func<T1, T2, TResult>Joined elements result selector.
Returns
- IEnumerable<TResult>
New IEnumerable<T> instance.
Type Parameters
T1
Outer collection element type.
T2
Inner collection element type.
TKey
Key type.
TResult
Result 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
outer
IEnumerable<T1>Outer collection.
inner
IEnumerable<T2>Inner collection.
outerKeySelector
Func<T1, TKey>Selector of outer collection element keys.
innerKeySelector
Func<T2, TKey>Selector of inner collection element keys.
resultSelector
Func<T1, T2, TResult>Joined elements result selector.
keyComparer
IEqualityComparer<TKey>Comparer to use for key equality comparison.
Returns
- IEnumerable<TResult>
New IEnumerable<T> instance.
Type Parameters
T1
Outer collection element type.
T2
Inner collection element type.
TKey
Key type.
TResult
Result type.
IsEmpty<T>(IEnumerable<T>)
Checks if the provided source
is empty.
[Pure]
public static bool IsEmpty<T>(this IEnumerable<T> source)
Parameters
source
IEnumerable<T>Source collection.
Returns
- bool
true when
source
is empty, otherwise false.
Type Parameters
T
Collection 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
source
IEnumerable<T>Source collection.
Returns
- bool
true when
source
is considered to be materialized, otherwise false.
Type Parameters
T
Collection 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
source
IEnumerable<T>Source collection.
Returns
- bool
true when
source
is considered to be memoized, otherwise false.
Type Parameters
T
Collection 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
source
IEnumerable<T>Source collection.
Returns
- bool
true when
source
is null or empty, otherwise false.
Type Parameters
T
Collection 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
source
IEnumerable<T>Source collection.
Returns
- bool
true when
source
is ordered, otherwise false.
Type Parameters
T
Collection 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
source
IEnumerable<T>Source collection.
comparer
IComparer<T>Comparer to use for value comparison.
Returns
- bool
true when
source
is ordered, otherwise false.
Type Parameters
T
Collection 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
outer
IEnumerable<T1>Outer collection.
inner
IEnumerable<T2>Inner collection.
outerKeySelector
Func<T1, TKey>Selector of outer collection element keys.
innerKeySelector
Func<T2, TKey>Selector of inner collection element keys.
resultSelector
Func<T1, T2, TResult>Joined elements result selector.
Returns
- IEnumerable<TResult>
New IEnumerable<T> instance.
Type Parameters
T1
Outer collection element type.
T2
Inner collection element type.
TKey
Key type.
TResult
Result 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
outer
IEnumerable<T1>Outer collection.
inner
IEnumerable<T2>Inner collection.
outerKeySelector
Func<T1, TKey>Selector of outer collection element keys.
innerKeySelector
Func<T2, TKey>Selector of inner collection element keys.
resultSelector
Func<T1, T2, TResult>Joined elements result selector.
keyComparer
IEqualityComparer<TKey>Comparer to use for key equality comparison.
Returns
- IEnumerable<TResult>
New IEnumerable<T> instance.
Type Parameters
T1
Outer collection element type.
T2
Inner collection element type.
TKey
Key type.
TResult
Result type.
Materialize<T>(IEnumerable<T>)
Materialized the provided source
.
[Pure]
public static IReadOnlyCollection<T> Materialize<T>(this IEnumerable<T> source)
Parameters
source
IEnumerable<T>Source collection.
Returns
- IReadOnlyCollection<T>
New IEnumerable<T> instance, or
source
when it is an instance of IReadOnlyCollection<T>, or memoized value whensource
is an instance of IMemoizedCollection<T>.
Type Parameters
T
Collection element type.
Memoize<T>(IEnumerable<T>)
Memoizes the provided source
.
[Pure]
public static IMemoizedCollection<T> Memoize<T>(this IEnumerable<T> source)
Parameters
source
IEnumerable<T>Source collection.
Returns
- IMemoizedCollection<T>
New IMemoizedCollection<T> instance, or
source
when it is an instance of IMemoizedCollection<T>.
Type Parameters
T
Collection 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
source
IEnumerable<T1>Source collection.
selector
Func<T1, T2>Selector of a value to use for comparison.
Returns
Type Parameters
T1
Collection element type.
T2
Value type used for comparison.
Exceptions
- InvalidOperationException
When
source
is 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
source
IEnumerable<T1>Source collection.
selector
Func<T1, T2>Selector of a value to use for comparison.
comparer
IComparer<T2>Comparer to use for value comparison.
Returns
Type Parameters
T1
Collection element type.
T2
Value type used for comparison.
Exceptions
- InvalidOperationException
When
source
is 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
source
IEnumerable<T1>Source collection.
minSelector
Func<T1, T2>Selector of a minimum value to use for comparison.
maxSelector
Func<T1, T3>Selector of a maximum value to use for comparison.
Returns
Type Parameters
T1
Collection element type.
T2
Type used for minimum value comparison.
T3
Type used for maximum value comparison.
Exceptions
- InvalidOperationException
When
source
is 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
source
IEnumerable<T1>Source collection.
minSelector
Func<T1, T2>Selector of a minimum value to use for comparison.
maxSelector
Func<T1, T3>Selector of a maximum value to use for comparison.
minComparer
IComparer<T2>Comparer to use for minimum value comparison.
maxComparer
IComparer<T3>Comparer to use for maximum value comparison.
Returns
Type Parameters
T1
Collection element type.
T2
Type used for minimum value comparison.
T3
Type used for maximum value comparison.
Exceptions
- InvalidOperationException
When
source
is 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
source
IEnumerable<T>Source collection.
Returns
Type Parameters
T
Collection element type.
Exceptions
- InvalidOperationException
When
source
is 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
source
IEnumerable<T>Source collection.
comparer
IComparer<T>Comparer to use for element comparison.
Returns
Type Parameters
T
Collection element type.
Exceptions
- InvalidOperationException
When
source
is 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
source
IEnumerable<T>Source collection.
predicate
Func<T, bool>Predicate to use for collection partitioning.
Returns
- PartitionResult<T>
New PartitionResult<T> instance.
Type Parameters
T
Collection 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
source
IEnumerable<T>Source collection.
count
intNumber of
source
repetitions.
Returns
- IEnumerable<T>
New IEnumerable<T> instance, or empty enumerable when
count
is equal to 0, orsource
whencount
is equal to 1 .
Type Parameters
T
Collection element type.
Exceptions
- ArgumentOutOfRangeException
When
count
is 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
source
IEnumerable<T>First collection.
other
IEnumerable<T>Second collection.
Returns
- bool
true when the two collections are equivalent sets, otherwise false.
Type Parameters
T
Element 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
source
IEnumerable<T>First collection.
other
IEnumerable<T>Second collection.
comparer
IEqualityComparer<T>Comparer to use for element comparison.
Returns
- bool
true when the two collections are equivalent sets, otherwise false.
Type Parameters
T
Element 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
source
IEnumerable<T>Source collection.
startIndex
intIndex of the first element to include in the slice.
length
intLength of the slice.
Returns
- IEnumerable<T>
New IEnumerable<T> instance, or an empty enumerable when
length
is less than 1 or when computed index of the last slice element is less than 1.
Type Parameters
T
Collection 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
source
IEnumerable<T>Source collection.
Returns
- ReadOnlyMemory<T>
New ReadOnlyMemory<T> instance.
Type Parameters
T
Collection 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
source
IEnumerable<T>Source collection.
func
Func<T, T, T>Aggregator delegate.
result
Tout parameter that contains aggregation result, when
source
is not empty.
Returns
- bool
true when
source
is not empty, otherwise false.
Type Parameters
T
Collection 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
source
IEnumerable<T1>Source collection.
selector
Func<T1, T2>Selector of a value to use for comparison.
comparer
IComparer<T2>Comparer to use for value comparison.
result
T1out parameter that contains the element with maximum value, if the collection is not empty.
Returns
- bool
true when
source
is not empty, otherwise false.
Type Parameters
T1
Collection element type.
T2
Value 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
source
IEnumerable<T1>Source collection.
selector
Func<T1, T2>Selector of a value to use for comparison.
result
T1out parameter that contains the element with maximum value, if the collection is not empty.
Returns
- bool
true when
source
is not empty, otherwise false.
Type Parameters
T1
Collection element type.
T2
Value 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
source
IEnumerable<T>Source collection.
comparer
IComparer<T>Comparer to use for element comparison.
result
Tout parameter that contains the maximum value, if the collection is not empty.
Returns
- bool
true when
source
is not empty, otherwise false.
Type Parameters
T
Collection 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
source
IEnumerable<T>Source collection.
result
Tout parameter that contains the maximum value, if the collection is not empty.
Returns
- bool
true when
source
is not empty, otherwise false.
Type Parameters
T
Collection 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
source
IEnumerable<T1>Source collection.
selector
Func<T1, T2>Selector of a value to use for comparison.
comparer
IComparer<T2>Comparer to use for value comparison.
result
T1out parameter that contains the element with minimum value, if the collection is not empty.
Returns
- bool
true when
source
is not empty, otherwise false.
Type Parameters
T1
Collection element type.
T2
Value 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
source
IEnumerable<T1>Source collection.
selector
Func<T1, T2>Selector of a value to use for comparison.
result
T1out parameter that contains the element with minimum value, if the collection is not empty.
Returns
- bool
true when
source
is not empty, otherwise false.
Type Parameters
T1
Collection element type.
T2
Value 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
source
IEnumerable<T1>Source collection.
selector
Func<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
source
is empty.
Type Parameters
T1
Collection element type.
T2
Value 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
source
IEnumerable<T1>Source collection.
selector
Func<T1, T2>Selector of a value to use for comparison.
comparer
IComparer<T2>Comparer to use for value comparison.
Returns
- (T1 Min, T1 Max)?
A tuple containing elements with Min and Max values, or null when
source
is empty.
Type Parameters
T1
Collection element type.
T2
Value 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
source
IEnumerable<T1>Source collection.
minSelector
Func<T1, T2>Selector of a minimum value to use for comparison.
maxSelector
Func<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
source
is empty.
Type Parameters
T1
Collection element type.
T2
Type used for minimum value comparison.
T3
Type 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
source
IEnumerable<T1>Source collection.
minSelector
Func<T1, T2>Selector of a minimum value to use for comparison.
maxSelector
Func<T1, T3>Selector of a maximum value to use for comparison.
minComparer
IComparer<T2>Comparer to use for minimum value comparison.
maxComparer
IComparer<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
source
is empty.
Type Parameters
T1
Collection element type.
T2
Type used for minimum value comparison.
T3
Type 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
source
IEnumerable<T>Source collection.
Returns
Type Parameters
T
Collection 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
source
IEnumerable<T>Source collection.
comparer
IComparer<T>Comparer to use for element comparison.
Returns
Type Parameters
T
Collection 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
source
IEnumerable<T>Source collection.
comparer
IComparer<T>Comparer to use for element comparison.
result
Tout parameter that contains the minimum value, if the collection is not empty.
Returns
- bool
true when
source
is not empty, otherwise false.
Type Parameters
T
Collection 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
source
IEnumerable<T>Source collection.
result
Tout parameter that contains the minimum value, if the collection is not empty.
Returns
- bool
true when
source
is not empty, otherwise false.
Type Parameters
T
Collection 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
source
IEnumerable<T>Source collection.
nodeRangeSelector
Func<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
T
Collection 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
source
IEnumerable<T>Source collection.
nodeRangeSelector
Func<T, IEnumerable<T>>Descendant node range selector.
stopPredicate
Func<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
T
Collection 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
source
IEnumerable<T?>Source collection.
Returns
- IEnumerable<T>
New IEnumerable<T> with null elements filtered out.
Type Parameters
T
Collection 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
source
IEnumerable<T>Source collection.
Returns
- IEnumerable<T>
New IEnumerable<T> with null elements filtered out.
Type Parameters
T
Collection 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
source
IEnumerable<T>Source collection.
comparer
IEqualityComparer<T>Element equality comparer.
Returns
- IEnumerable<T>
New IEnumerable<T> with null elements filtered out, or
source
when element type is a non-nullable value type.
Type Parameters
T
Collection element type.