Class MoreLinqExtensions
- Namespace
- Garyon.Extensions
- Assembly
- Garyon.dll
Provides more LINQ-like extensions that are not that likely to be considered candidates for being imported into System.Linq.
public static class MoreLinqExtensions
- Inheritance
-
MoreLinqExtensions
- Inherited Members
Methods
AnyDeep<T>(IEnumerable<IEnumerable<T>>)
Determines whether there are any elements contained in any sequence of the sequences that are provided.
public static bool AnyDeep<T>(this IEnumerable<IEnumerable<T>> source)
Parameters
sourceIEnumerable<IEnumerable<T>>The sequence of sequences to analyze on whether any elements are contained.
Returns
Type Parameters
TThe type of elements stored in the sequences.
Apply<TSource>(TSource, Action<TSource>)
Applies a function to the given value and returns the same value.
public static TSource Apply<TSource>(this TSource source, Action<TSource> function)
Parameters
sourceTSourceThe source value.
functionAction<TSource>The function to apply to the source value.
Returns
- TSource
The same source value for chaining purposes.
Type Parameters
TSourceThe type of the source value.
Apply<TSource, TResult>(TSource, Func<TSource, TResult>)
Applies a function to the given value and returns the result.
public static TResult Apply<TSource, TResult>(this TSource source, Func<TSource, TResult> function)
Parameters
sourceTSourceThe source value.
functionFunc<TSource, TResult>The function to apply to the source value.
Returns
- TResult
The resulting value after applying
functiontosource.
Type Parameters
TSourceThe type of the source value.
TResultThe type of the result value.
CountAtLeast<T>(IEnumerable<T>, Func<T, bool>, int)
Determines whether there are at least a specified number of occurrences of elements meeting a condition in a collection.
public static bool CountAtLeast<T>(this IEnumerable<T> source, Func<T, bool> predicate, int occurrences)
Parameters
sourceIEnumerable<T>The source collection whose elements to compare against the condition.
predicateFunc<T, bool>The condition that the elements must meet.
occurrencesintThe minimum number of elements that must meet the condition.
Returns
- bool
true if the provided collection contains at least
occurrenceselements that meet the given condition, otherwise false.
Type Parameters
TThe type of the elements in the collection.
CountAtLeast<T>(IEnumerable<T>, int)
Determines whether there are at least a specified number of occurrences of elements in an enumerable.
public static bool CountAtLeast<T>(this IEnumerable<T> source, int minCount)
Parameters
sourceIEnumerable<T>minCountintThe minimum number of elements that must exist in the enumerable.
Returns
Type Parameters
T
CountAtMost<T>(IEnumerable<T>, Func<T, bool>, int)
Determines whether there are at most a specified number of occurrences of elements meeting a condition in a collection.
public static bool CountAtMost<T>(this IEnumerable<T> source, Func<T, bool> predicate, int occurrences)
Parameters
sourceIEnumerable<T>The source collection whose elements to compare against the condition.
predicateFunc<T, bool>The condition that the elements must meet.
occurrencesintThe minimum number of elements that must meet the condition.
Returns
- bool
true if the provided collection contains at least
occurrenceselements that meet the given condition, otherwise false.
Type Parameters
TThe type of the elements in the collection.
CountAtMost<T>(IEnumerable<T>, int)
Determines whether there are at most a specified number of occurrences of elements in an enumerable.
public static bool CountAtMost<T>(this IEnumerable<T> source, int maxCount)
Parameters
sourceIEnumerable<T>maxCountintThe maximum number of elements that must exist in the enumerable.
Returns
Type Parameters
T
CountBetween<T>(IEnumerable<T>, Func<T, bool>, int, int)
Determines whether there are between a specified range (inclusive) of occurrences of elements meeting a condition in a collection.
public static bool CountBetween<T>(this IEnumerable<T> source, Func<T, bool> predicate, int minOccurrences, int maxOccurrences)
Parameters
sourceIEnumerable<T>The source collection whose elements to compare against the condition.
predicateFunc<T, bool>The condition that the elements must meet.
minOccurrencesintThe minimum number of elements that must meet the given condition.
maxOccurrencesintThe maximum number of elements that may meet the given condition.
Returns
- bool
true if the provided collection contains between
minOccurrencesandmaxOccurrences(inclusive) elements that meet the given condition, otherwise false.
Type Parameters
TThe type of the elements in the collection.
CountBetween<T>(IEnumerable<T>, int, int)
Determines whether there are between a specified range (inclusive) of occurrences of elements in an enumerable.
public static bool CountBetween<T>(this IEnumerable<T> source, int minCount, int maxCount)
Parameters
sourceIEnumerable<T>minCountintThe minimum number of elements that must exist in the enumerable.
maxCountintThe maximum number of elements that may exist in the enumerable.
Returns
- bool
true if the provided collection contains between
minCountandmaxCount(inclusive) elements, otherwise false.
Type Parameters
T
CountExactly<T>(IEnumerable<T>, Func<T, bool>, int)
Determines whether there are exactly a specified number of occurrences of elements meeting a condition in a collection.
public static bool CountExactly<T>(this IEnumerable<T> source, Func<T, bool> predicate, int occurrences)
Parameters
sourceIEnumerable<T>The source collection whose elements to compare against the condition.
predicateFunc<T, bool>The condition that the elements must meet.
occurrencesintThe exact number of elements that must meet the given condition.
Returns
- bool
true if the provided collection contains exactly
occurrenceselements that meet the given condition, otherwise false.
Type Parameters
TThe type of the elements in the collection.
CountExactly<T>(IEnumerable<T>, int)
Determines whether there are exactly a specified number of occurrences of elements in an enumerable.
public static bool CountExactly<T>(this IEnumerable<T> source, int count)
Parameters
sourceIEnumerable<T>countintThe exact number of elements that must exist in the enumerable.
Returns
Type Parameters
T
EnumeratePerformAction<T>(IEnumerable<T>, Action<T>?, Action<T>?, Action<T>)
Performs an action for each element in a collection, while also performing an additional specified action for the first and the last elements.
public static bool EnumeratePerformAction<T>(this IEnumerable<T> source, Action<T>? firstElementAction, Action<T>? lastElementAction, Action<T> enumerationAction)
Parameters
sourceIEnumerable<T>The source collection whose elements to perform the actions on. If the collection is empty, no action will be taken.
firstElementActionAction<T>The action to perform on the first element.
lastElementActionAction<T>The action to perform on the last element.
enumerationActionAction<T>The action to perform on all enumerated elements. This is also applied to the first and the last elements.
Returns
Type Parameters
TThe type of the elements in the collection.
NotNullCount<T>(IEnumerable<T>)
Gets the count of elements that are not null.
public static int NotNullCount<T>(this IEnumerable<T> source)
Parameters
sourceIEnumerable<T>The IEnumerable<T> whose elements to iterate.
Returns
Type Parameters
TThe type of the elements stored in the IEnumerable<T>.
NullCount<T>(IEnumerable<T>)
Gets the count of elements that are not null.
public static int NullCount<T>(this IEnumerable<T> source)
Parameters
sourceIEnumerable<T>The IEnumerable<T> whose elements to iterate.
Returns
Type Parameters
TThe type of the elements stored in the IEnumerable<T>.
OnlyOrDefault<T>(IEnumerable<T>?)
Gets the only element of the sequence, if it only has one element, otherwise returns default.
public static T? OnlyOrDefault<T>(this IEnumerable<T>? source)
Parameters
sourceIEnumerable<T>The source sequence.
Returns
- T
The only element of the sequence, or default.
Type Parameters
TThe type of the elements in the sequence.
SelectOrDefault<TSource, TResult>(IEnumerable<TSource>, Func<TSource, TResult>?)
Selects the enumerable's items based on a selector. If the selector is null, a null enumerable is returned instead.
public static IEnumerable<TResult>? SelectOrDefault<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult>? selector)
Parameters
sourceIEnumerable<TSource>selectorFunc<TSource, TResult>
Returns
- IEnumerable<TResult>
Type Parameters
TSourceTResult
ToListDictionary<TKey, TValue>(IEnumerable<IGrouping<TKey, TValue>>)
Converts all groupings to a dictionary, with the values being a List<T>.
public static Dictionary<TKey, List<TValue>> ToListDictionary<TKey, TValue>(this IEnumerable<IGrouping<TKey, TValue>> groupings) where TKey : notnull
Parameters
groupingsIEnumerable<IGrouping<TKey, TValue>>
Returns
- Dictionary<TKey, List<TValue>>
Type Parameters
TKeyTValue
WhereNotNullKeys<TKey, TValue>(IEnumerable<IGrouping<TKey?, TValue>>)
Filters all groupings and returns only those that have non-null keys.
public static IEnumerable<IGrouping<TKey, TValue>> WhereNotNullKeys<TKey, TValue>(this IEnumerable<IGrouping<TKey?, TValue>> grouping)
Parameters
groupingIEnumerable<IGrouping<TKey, TValue>>
Returns
- IEnumerable<IGrouping<TKey, TValue>>
Type Parameters
TKeyTValue
WhereNotNull<T>(IEnumerable<T?>)
Filters the items and returns only those that are not null.
public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> source)
Parameters
sourceIEnumerable<T>
Returns
- IEnumerable<T>
Type Parameters
T
WhereNot<T>(IEnumerable<T>, Func<T, bool>)
Checks all elements against a predicate and returns only those elements that do NOT meet the condition.
public static IEnumerable<T> WhereNot<T>(this IEnumerable<T> source, Func<T, bool> predicate)
Parameters
sourceIEnumerable<T>The sequence of elements to filter.
predicateFunc<T, bool>A function to test each element for a condition. Elements for which this function returns false are included in the result.
Returns
- IEnumerable<T>
Type Parameters
T
WhereOrSource<T>(IEnumerable<T>, Func<T, bool>?)
Filters out the contents of the enumerable, if a predicate is provided. Otherwise, returns the source enumerable as-is.
public static IEnumerable<T> WhereOrSource<T>(this IEnumerable<T> source, Func<T, bool>? predicate)
Parameters
sourceIEnumerable<T>predicateFunc<T, bool>
Returns
- IEnumerable<T>
Type Parameters
T
WherePredicate<T>(IEnumerable<T>, Predicate<T>)
Filters a sequence of values based on a predicate.
public static IEnumerable<T> WherePredicate<T>(this IEnumerable<T> source, Predicate<T> predicate)
Parameters
sourceIEnumerable<T>An IEnumerable<T> to filter.
predicatePredicate<T>A function to test each element for a condition.
Returns
- IEnumerable<T>
An IEnumerable<T> that contains elements from the input sequence that satisfy the condition.
Type Parameters
T
Exceptions
- ArgumentNullException
sourceorpredicateis null.
Zip<TA, TB>(IEnumerable<TA>, IEnumerable<TB>)
Zips both sequences into a sequence of tuples.
public static IEnumerable<(TA First, TB Second)> Zip<TA, TB>(this IEnumerable<TA> source, IEnumerable<TB> other)
Parameters
sourceIEnumerable<TA>otherIEnumerable<TB>
Returns
- IEnumerable<(TA First, TB Second)>
Type Parameters
TATB