NanoByte.Common  2.6.1
NanoByte.Common.Collections.EnumerableExtensions Class Reference

Provides extension methods for IEnumerable<T>s. More...

Static Public Member Functions

static bool ContainsOrEmpty< T > (this IEnumerable< T > enumeration, T element)
 Determines whether the enumeration contains an element or is null. More...
 
static bool ContainsAny< T > (this IEnumerable< T > first, IEnumerable< T > second, IEqualityComparer< T >? comparer=null)
 Determines whether one enumeration of elements contains any of the elements in another. More...
 
static bool SequencedEquals< T > (this IEnumerable< T > first, IEnumerable< T > second, IEqualityComparer< T >? comparer=null)
 Determines whether two enumerations contain the same elements in the same order. More...
 
static bool UnsequencedEquals< T > (this IEnumerable< T > first, IEnumerable< T > second, IEqualityComparer< T >? comparer=null)
 Determines whether two enumerations contain the same elements disregarding the order they are in. More...
 
static int GetSequencedHashCode< T > (this IEnumerable< T > enumeration, IEqualityComparer< T >? comparer=null)
 Generates a hash code for the contents of the enumeration. Changing the elements' order will change the hash. More...
 
static int GetUnsequencedHashCode< T > (this IEnumerable< T > enumeration, IEqualityComparer< T >? comparer=null)
 Generates a hash code for the contents of the enumeration. Changing the elements' order will not change the hash. More...
 
static IEnumerable< T > Except< T > (this IEnumerable< T > enumeration, Func< T, bool > predicate)
 Filters a sequence of elements to remove any that match the predicate . The opposite of Enumerable.Where<TSource>(IEnumerable<TSource>,Func<TSource,bool>). More...
 
static IEnumerable< T > Except< T > (this IEnumerable< T > enumeration, T element)
 Filters a sequence of elements to remove any that are equal to element . More...
 
static IEnumerable< T > Flatten< T > (this IEnumerable< IEnumerable< T >> enumeration)
 Flattens a list of lists. More...
 
static IEnumerable< T > Append< T > (this IEnumerable< T > enumeration, T element)
 Appends an element to a list. More...
 
static IEnumerable< T > Prepend< T > (this IEnumerable< T > enumeration, T element)
 Prepends an element to a list. More...
 
static IEnumerable< T > WhereNotNull< T > (this IEnumerable< T?> enumeration)
 Filters a sequence of elements to remove any null values. More...
 
static T MaxBy< T, TValue > (this IEnumerable< T > enumeration, Func< T, TValue > expression, IComparer< TValue >? comparer=null)
 Determines the element in a list that maximizes a specified expression. More...
 
static T MinBy< T, TValue > (this IEnumerable< T > enumeration, Func< T, TValue > expression, IComparer< TValue >? comparer=null)
 Determines the element in a list that minimizes a specified expression. More...
 
static IEnumerable< T > DistinctBy< T, TKey > (this IEnumerable< T > enumeration, Func< T, TKey > keySelector)
 Filters a sequence of elements to remove any duplicates based on the equality of a key extracted from the elements. More...
 
static IEnumerable< TResult > TrySelect< TSource, TResult, TException > (this IEnumerable< TSource > source, Func< TSource, TResult > selector)
 Maps elements like Enumerable.Select<TSource,TResult>(IEnumerable<TSource>,Func<TSource,TResult>), but with exception handling. More...
 
static IEnumerable< T > CloneElements< T > (this IEnumerable< T > enumerable)
 Calls ICloneable<T>.Clone for every element in a enumeration and returns the results as a new enumeration. More...
 
static IEnumerable< T > TopologicalSort< T > (this IEnumerable< T > nodes, Func< T, IEnumerable< T >> getDependencies)
 Performs a topological sort of an object graph. More...
 
static async Task ForEachAsync< T > (this IEnumerable< T > enumerable, Func< T, Task > taskFactory, int maxParallel=0)
 Runs asynchronous operations for each element in an enumeration. Runs multiple tasks using cooperative multitasking. More...
 
static IEnumerable< T[]> Permutate< T > (this IEnumerable< T > elements)
 Generates all possible permutations of a set of elements . More...
 

Detailed Description

Provides extension methods for IEnumerable<T>s.

Member Function Documentation

◆ Append< T >()

static IEnumerable<T> NanoByte.Common.Collections.EnumerableExtensions.Append< T > ( this IEnumerable< T >  enumeration,
element 
)
static

Appends an element to a list.

◆ CloneElements< T >()

static IEnumerable<T> NanoByte.Common.Collections.EnumerableExtensions.CloneElements< T > ( this IEnumerable< T >  enumerable)
static

Calls ICloneable<T>.Clone for every element in a enumeration and returns the results as a new enumeration.

Type Constraints
T :ICloneable<T> 
T :enumerable 
T :throw 
T :new 
T :ArgumentNullException 
T :nameof 
T :enumerable 
T :Select 
T :x 
T :x.Clone() 

◆ ContainsAny< T >()

static bool NanoByte.Common.Collections.EnumerableExtensions.ContainsAny< T > ( this IEnumerable< T >  first,
IEnumerable< T >  second,
IEqualityComparer< T >?  comparer = null 
)
inlinestatic

Determines whether one enumeration of elements contains any of the elements in another.

Parameters
firstThe first of the two enumerations to compare.
secondThe first of the two enumerations to compare.
comparerControls how to compare elements; leave null for default comparer.
Returns
true if first contains any element from second . false if first or second is empty.

◆ ContainsOrEmpty< T >()

static bool NanoByte.Common.Collections.EnumerableExtensions.ContainsOrEmpty< T > ( this IEnumerable< T >  enumeration,
element 
)
inlinestatic

Determines whether the enumeration contains an element or is null.

Parameters
enumerationThe list to check.
elementThe element to look for.

Useful for lists that contain an OR-ed list of restrictions, where an empty list means no restrictions.

◆ DistinctBy< T, TKey >()

static IEnumerable<T> NanoByte.Common.Collections.EnumerableExtensions.DistinctBy< T, TKey > ( this IEnumerable< T >  enumeration,
Func< T, TKey >  keySelector 
)
static

Filters a sequence of elements to remove any duplicates based on the equality of a key extracted from the elements.

Parameters
enumerationThe sequence of elements to filter.
keySelectorA function mapping elements to their respective equality keys.
Type Constraints
T :notnull 
TKey :notnull 
TKey :enumeration.Distinct 
TKey :new 
TKey :KeyEqualityComparer 
TKey :T 
TKey :TKey 
TKey :keySelector 

◆ Except< T >() [1/2]

static IEnumerable<T> NanoByte.Common.Collections.EnumerableExtensions.Except< T > ( this IEnumerable< T >  enumeration,
Func< T, bool >  predicate 
)
static

Filters a sequence of elements to remove any that match the predicate . The opposite of Enumerable.Where<TSource>(IEnumerable<TSource>,Func<TSource,bool>).

◆ Except< T >() [2/2]

static IEnumerable<T> NanoByte.Common.Collections.EnumerableExtensions.Except< T > ( this IEnumerable< T >  enumeration,
element 
)
static

Filters a sequence of elements to remove any that are equal to element .

◆ Flatten< T >()

static IEnumerable<T> NanoByte.Common.Collections.EnumerableExtensions.Flatten< T > ( this IEnumerable< IEnumerable< T >>  enumeration)
static

Flattens a list of lists.

◆ ForEachAsync< T >()

static async Task NanoByte.Common.Collections.EnumerableExtensions.ForEachAsync< T > ( this IEnumerable< T >  enumerable,
Func< T, Task >  taskFactory,
int  maxParallel = 0 
)
inlinestatic

Runs asynchronous operations for each element in an enumeration. Runs multiple tasks using cooperative multitasking.

Parameters
enumerableThe input elements to enumerate over.
taskFactoryCreates a Task for each input element.
maxParallelThe maximum number of Tasks to run in parallel. Use 0 or lower for unbounded.
Exceptions
InvalidOperationExceptionTaskScheduler.Current is equal to TaskScheduler.Default.

SynchronizationContext.Current must not be null. The synchronization context is required to ensure that task continuations are scheduled sequentially and do not run in parallel.

◆ GetSequencedHashCode< T >()

static int NanoByte.Common.Collections.EnumerableExtensions.GetSequencedHashCode< T > ( this IEnumerable< T >  enumeration,
IEqualityComparer< T >?  comparer = null 
)
inlinestatic

Generates a hash code for the contents of the enumeration. Changing the elements' order will change the hash.

Parameters
enumerationThe enumeration to generate the hash for.
comparerControls how to compare elements; leave null for default comparer.
See also
SequencedEquals<T>

◆ GetUnsequencedHashCode< T >()

static int NanoByte.Common.Collections.EnumerableExtensions.GetUnsequencedHashCode< T > ( this IEnumerable< T >  enumeration,
IEqualityComparer< T >?  comparer = null 
)
inlinestatic

Generates a hash code for the contents of the enumeration. Changing the elements' order will not change the hash.

Parameters
enumerationThe enumeration to generate the hash for.
comparerControls how to compare elements; leave null for default comparer.
See also
UnsequencedEquals<T>

◆ MaxBy< T, TValue >()

static T NanoByte.Common.Collections.EnumerableExtensions.MaxBy< T, TValue > ( this IEnumerable< T >  enumeration,
Func< T, TValue >  expression,
IComparer< TValue >?  comparer = null 
)
inlinestatic

Determines the element in a list that maximizes a specified expression.

Template Parameters
TThe type of the elements.
TValueThe type of the expression .
Parameters
enumerationThe elements to check.
expressionThe expression to maximize.
comparerControls how to compare elements; leave null for default comparer.
Returns
The element that maximizes the expression.
Exceptions
InvalidOperationExceptionenumeration contains no elements.

◆ MinBy< T, TValue >()

static T NanoByte.Common.Collections.EnumerableExtensions.MinBy< T, TValue > ( this IEnumerable< T >  enumeration,
Func< T, TValue >  expression,
IComparer< TValue >?  comparer = null 
)
inlinestatic

Determines the element in a list that minimizes a specified expression.

Template Parameters
TThe type of the elements.
TValueThe type of the expression .
Parameters
enumerationThe elements to check.
expressionThe expression to minimize.
comparerControls how to compare elements; leave null for default comparer.
Returns
The element that minimizes the expression.
Exceptions
InvalidOperationExceptionenumeration contains no elements.

◆ Permutate< T >()

static IEnumerable<T[]> NanoByte.Common.Collections.EnumerableExtensions.Permutate< T > ( this IEnumerable< T >  elements)
inlinestatic

Generates all possible permutations of a set of elements .

◆ Prepend< T >()

static IEnumerable<T> NanoByte.Common.Collections.EnumerableExtensions.Prepend< T > ( this IEnumerable< T >  enumeration,
element 
)
static

Prepends an element to a list.

◆ SequencedEquals< T >()

static bool NanoByte.Common.Collections.EnumerableExtensions.SequencedEquals< T > ( this IEnumerable< T >  first,
IEnumerable< T >  second,
IEqualityComparer< T >?  comparer = null 
)
inlinestatic

Determines whether two enumerations contain the same elements in the same order.

Parameters
firstThe first of the two enumerations to compare.
secondThe first of the two enumerations to compare.
comparerControls how to compare elements; leave null for default comparer.

◆ TopologicalSort< T >()

static IEnumerable<T> NanoByte.Common.Collections.EnumerableExtensions.TopologicalSort< T > ( this IEnumerable< T >  nodes,
Func< T, IEnumerable< T >>  getDependencies 
)
inlinestatic

Performs a topological sort of an object graph.

Parameters
nodesThe set of nodes to sort.
getDependenciesA function that retrieves all dependencies of a node.
Exceptions
InvalidDataExceptionCyclic dependency found.

◆ TrySelect< TSource, TResult, TException >()

static IEnumerable<TResult> NanoByte.Common.Collections.EnumerableExtensions.TrySelect< TSource, TResult, TException > ( this IEnumerable< TSource >  source,
Func< TSource, TResult >  selector 
)
inlinestatic

Maps elements like Enumerable.Select<TSource,TResult>(IEnumerable<TSource>,Func<TSource,TResult>), but with exception handling.

Template Parameters
TSourceThe type of the input elements.
TResultThe type of the output elements.
TExceptionThe type of exceptions to ignore. Any other exceptions are passed through.
Parameters
sourceThe elements to map.
selectorThe selector to execute for each source element. When it throws TException the element is skipped. Any other exceptions are passed through.
Type Constraints
TException :Exception 

◆ UnsequencedEquals< T >()

static bool NanoByte.Common.Collections.EnumerableExtensions.UnsequencedEquals< T > ( this IEnumerable< T >  first,
IEnumerable< T >  second,
IEqualityComparer< T >?  comparer = null 
)
inlinestatic

Determines whether two enumerations contain the same elements disregarding the order they are in.

Parameters
firstThe first of the two enumerations to compare.
secondThe first of the two enumerations to compare.
comparerControls how to compare elements; leave null for default comparer.

◆ WhereNotNull< T >()

static IEnumerable<T> NanoByte.Common.Collections.EnumerableExtensions.WhereNotNull< T > ( this IEnumerable< T?>  enumeration)
inlinestatic

Filters a sequence of elements to remove any null values.

Type Constraints
T :class 

The documentation for this class was generated from the following file: