Table of Contents

Class EnumerableExtensions

Namespace
ChartTools.Extensions.Linq
Assembly
ChartTools.dll
public static class EnumerableExtensions
Inheritance
EnumerableExtensions
Inherited Members

Methods

All(IEnumerable<bool>)

Checks that all booleans in a collection are true.

public static bool All(this IEnumerable<bool> source)

Parameters

source IEnumerable<bool>

Source of booleans

Returns

bool

true if all booleans are true or the collection is empty

AlternateBy<T, TKey>(IEnumerable<IEnumerable<T>>, Func<T, TKey>)

public static IEnumerable<T> AlternateBy<T, TKey>(this IEnumerable<IEnumerable<T>> source, Func<T, TKey> selector) where TKey : IComparable<TKey>

Parameters

source IEnumerable<IEnumerable<T>>
selector Func<T, TKey>

Returns

IEnumerable<T>

Type Parameters

T
TKey

Alternate<T>(IEnumerable<IEnumerable<T>>)

public static IEnumerable<T> Alternate<T>(this IEnumerable<IEnumerable<T>> source)

Parameters

source IEnumerable<IEnumerable<T>>

Returns

IEnumerable<T>

Type Parameters

T

Any(IEnumerable<bool>)

Checks if any boolean in a collection is true.

public static bool Any(this IEnumerable<bool> source)

Parameters

source IEnumerable<bool>

Source of booleans

Returns

bool

Distinct<T>(IEnumerable<T>, EqualityComparison<T?>)

Returns distinct elements of a sequence using a method to determine the equality of elements

public static IEnumerable<T> Distinct<T>(this IEnumerable<T> source, EqualityComparison<T?> comparison)

Parameters

source IEnumerable<T>
comparison EqualityComparison<T>

Method that determines if two elements are the same

Returns

IEnumerable<T>

Type Parameters

T

FirstOrDefault<T>(IEnumerable<T>, Predicate<T>, T?, out bool)

Returns the first element of the sequence that satisfies a condition or a default value if no such element is found.

public static T? FirstOrDefault<T>(this IEnumerable<T> source, Predicate<T> predicate, T? defaultValue, out bool returnedDefault)

Parameters

source IEnumerable<T>

An IEnumerable<T> to return an element from.

predicate Predicate<T>

A function to test each element for a condition.

defaultValue T
returnedDefault bool

true if no items meeting the condition were found

Returns

T

default(TSource) if source is empty or if no element passes the test specified by predicate; otherwise, the first element in source that passes the test specified by predicate.

Type Parameters

T

Exceptions

ArgumentNullException

source or predicate is null.

ManyMaxBy<T, TKey>(IEnumerable<T>, Func<T, TKey>)

Finds the items for which a function returns the greatest value.

public static IEnumerable<T> ManyMaxBy<T, TKey>(this IEnumerable<T> source, Func<T, TKey> selector) where TKey : IComparable<TKey>

Parameters

source IEnumerable<T>

Items to find the minimum or maximum of

selector Func<T, TKey>

Function that gets the key to use in the comparison from an item

Returns

IEnumerable<T>

Type Parameters

T
TKey

ManyMinBy<T, TKey>(IEnumerable<T>, Func<T, TKey>)

Finds the items for which a function returns the smallest value.

public static IEnumerable<T> ManyMinBy<T, TKey>(this IEnumerable<T> source, Func<T, TKey> selector) where TKey : IComparable<TKey>

Parameters

source IEnumerable<T>

Items to find the minimum or maximum of

selector Func<T, TKey>

Function that gets the key to use in the comparison from an item

Returns

IEnumerable<T>

Type Parameters

T
TKey

NonNull<T>(IEnumerable<T?>)

public static IEnumerable<T> NonNull<T>(this IEnumerable<T?> source) where T : struct

Parameters

source IEnumerable<T?>

Returns

IEnumerable<T>

Type Parameters

T

NonNull<T>(IEnumerable<T?>)

Excludes null items.

public static IEnumerable<T> NonNull<T>(this IEnumerable<T?> source)

Parameters

source IEnumerable<T>

Returns

IEnumerable<T>

Type Parameters

T

RelativeLoopSkipFirst<T>(IEnumerable<T>)

public static IEnumerable<(T previous, T current)> RelativeLoopSkipFirst<T>(this IEnumerable<T> source)

Parameters

source IEnumerable<T>

Returns

IEnumerable<(T previous, T current)>

Type Parameters

T

RelativeLoop<T>(IEnumerable<T>, T?)

Loops through a set of objects and returns a set of tuples containing the current object and the previous one.

public static IEnumerable<(T? previous, T current)> RelativeLoop<T>(this IEnumerable<T> source, T? firstPrevious = default)

Parameters

source IEnumerable<T>

Items to loop through

firstPrevious T

Value of the previous item in the first call of the action

Returns

IEnumerable<(T previous, T current)>

Type Parameters

T

RemoveSection<T>(IEnumerable<T>, Predicate<T>, Predicate<T>)

Removes a section of items.

public static IEnumerable<T> RemoveSection<T>(this IEnumerable<T> source, Predicate<T> startRemove, Predicate<T> endRemove)

Parameters

source IEnumerable<T>

Source items to remove a section of

startRemove Predicate<T>

Function that determines the start of the section to replace

endRemove Predicate<T>

Function that determines the end of the section to replace

Returns

IEnumerable<T>

Type Parameters

T

Remarks

Items that match startRemove or endRemove

ReplaceSection<T>(IEnumerable<T>, SectionReplacement<T>)

Replaces a section with other items.

public static IEnumerable<T> ReplaceSection<T>(this IEnumerable<T> source, SectionReplacement<T> replacement)

Parameters

source IEnumerable<T>

Items to replace a section in

replacement SectionReplacement<T>

Returns

IEnumerable<T>

Type Parameters

T

Remarks

Items that match startReplace or endReplace are not included in the returned items.

ReplaceSections<T>(IEnumerable<T>, IEnumerable<SectionReplacement<T>>)

Replaces multiple sections of items.

public static IEnumerable<T> ReplaceSections<T>(this IEnumerable<T> source, IEnumerable<SectionReplacement<T>> replacements)

Parameters

source IEnumerable<T>

Items to replace sections in

replacements IEnumerable<SectionReplacement<T>>

Returns

IEnumerable<T>

Type Parameters

T

Remarks

Items that match startReplace or endReplace are not included in the returned items.

Replace<T>(IEnumerable<T>, Predicate<T>, T)

Replaces items that meet a condition with another item.

public static IEnumerable<T> Replace<T>(this IEnumerable<T> source, Predicate<T> predicate, T replacement)

Parameters

source IEnumerable<T>

The IEnumerable<out T> to replace the items of

predicate Predicate<T>

A function that determines if an item must be replaced

replacement T

The item to replace items with

Returns

IEnumerable<T>

Type Parameters

T

ToAsyncEnumerable<T>(IEnumerable<T>)

public static IAsyncEnumerable<T> ToAsyncEnumerable<T>(this IEnumerable<T> source)

Parameters

source IEnumerable<T>

Returns

IAsyncEnumerable<T>

Type Parameters

T

TryGetFirstOfType<TResult>(IEnumerable, out TResult)

Tries to get the first item of a given type in a collection.

public static bool TryGetFirstOfType<TResult>(this IEnumerable source, out TResult result)

Parameters

source IEnumerable

Source of items

result TResult

Found item

Returns

bool

true if an item was found

Type Parameters

TResult

TryGetFirst<T>(IEnumerable<T>, Predicate<T>, out T)

Tries to get the first item that meet a condition from en enumerable.

public static bool TryGetFirst<T>(this IEnumerable<T> source, Predicate<T> predicate, out T item)

Parameters

source IEnumerable<T>
predicate Predicate<T>

Method that returns true if a given item meets the condition

item T

Found item

Returns

bool

true if an item was found

Type Parameters

T

TryGetFirst<T>(IEnumerable<T>, out T)

Tries to get the first element of a collection.

public static bool TryGetFirst<T>(this IEnumerable<T> source, out T result)

Parameters

source IEnumerable<T>

Source of items

result T

Found item

Returns

bool

true if an item was found

Type Parameters

T

UniqueBy<T, TKey>(IEnumerable<T>, Func<T, TKey>)

public static bool UniqueBy<T, TKey>(this IEnumerable<T> source, Func<T, TKey> selector)

Parameters

source IEnumerable<T>
selector Func<T, TKey>

Returns

bool

Type Parameters

T
TKey

Unique<T>(IEnumerable<T>)

public static bool Unique<T>(this IEnumerable<T> source)

Parameters

source IEnumerable<T>

Returns

bool

Type Parameters

T