Class LinqExtensions
Extensions for sets and lists.
public static class LinqExtensions
- Inheritance
-
LinqExtensions
- Inherited Members
Methods
AsArray<T>(T)
Convert a single element into an array with that element.
public static T[] AsArray<T>(this T element)
Parameters
elementT
Returns
- T[]
Type Parameters
T
Consume(IEnumerator)
Consume a single element from the enumerator.
public static object? Consume(this IEnumerator source)
Parameters
sourceIEnumerator
Returns
Consume<T>(IEnumerator, T)
Consume an element from the source or return the default value.
public static T Consume<T>(this IEnumerator source, T defaultValue = default)
Parameters
sourceIEnumeratordefaultValueT
Returns
- T
Type Parameters
T
Expand<T>(T[], IEnumerable<T>)
Create a new array with the other elements appended on the end.
public static T[] Expand<T>(this T[] source, IEnumerable<T> other)
Parameters
sourceT[]otherIEnumerable<T>
Returns
- T[]
Type Parameters
T
Foreach<T>(IEnumerable<T>, Action<T>)
Itterate over each element in the enumerable and preform the specified action on it.
public static void Foreach<T>(this IEnumerable<T> enumerable, Action<T> action)
Parameters
enumerableIEnumerable<T>actionAction<T>
Type Parameters
T
GetOrSet<Key, Value>(Dictionary<Key, Value>, Key, Func<Value>)
Get or set the specified key in the dictionary.
public static Value GetOrSet<Key, Value>(this Dictionary<Key, Value> dictionary, Key key, Func<Value> create) where Key : notnull
Parameters
dictionaryDictionary<Key, Value>keyKeycreateFunc<Value>
Returns
- Value
Type Parameters
KeyValue
InnerZip<T, U>(IEnumerable<T>, IEnumerable<U>)
Zip the lists together, zipping only the elements that exist in both lists.
public static IEnumerable<(T left, U right)> InnerZip<T, U>(this IEnumerable<T> left, IEnumerable<U> right)
Parameters
leftIEnumerable<T>rightIEnumerable<U>
Returns
- IEnumerable<(T left, U right)>
Type Parameters
TU
OuterZip<T, U>(IEnumerable<T>, IEnumerable<U>, T, U)
Zips the lists together, padding with the provided defaults if one list is longer then the other.
public static IEnumerable<(T left, U right)> OuterZip<T, U>(this IEnumerable<T> left, IEnumerable<U> right, T defaultLeft = default, U defaultRight = default)
Parameters
leftIEnumerable<T>rightIEnumerable<U>defaultLeftTdefaultRightU
Returns
- IEnumerable<(T left, U right)>
Type Parameters
TU
PadWith<T>(IEnumerable<T>, int, T)
Pad the enumerable to a specified length with the specified element, or the default(T).
public static IEnumerable<T> PadWith<T>(this IEnumerable<T> values, int length, T element = default)
Parameters
valuesIEnumerable<T>lengthintelementT
Returns
- IEnumerable<T>
Type Parameters
T
Take<T, U>(IEnumerable)
Take 2 elements from the array of type T and U.
public static (T?, U?) Take<T, U>(this IEnumerable source)
Parameters
sourceIEnumerable
Returns
- (T, U)
Type Parameters
TU
Take<T, U, V>(IEnumerable)
Take 3 elements form the array of type T, U and V.
public static (T?, U?, V?) Take<T, U, V>(this IEnumerable source)
Parameters
sourceIEnumerable
Returns
- (T, U, V)
Type Parameters
TUV
Take<T, U, V, W>(IEnumerable)
Take 3 elements form the array of type T, U, V and W.
public static (T?, U?, V?, W?) Take<T, U, V, W>(this IEnumerable source)
Parameters
sourceIEnumerable
Returns
- (T, U, V, W)
Type Parameters
TUVW
Take<T, U, V, W, X>(IEnumerable)
Take 5 elements of type T, U, V, W and X
public static (T?, U?, V?, W?, X?) Take<T, U, V, W, X>(this IEnumerable source)
Parameters
sourceIEnumerable
Returns
- (T, U, V, W, X)
Type Parameters
TUVWX
Take<T, U, V, W, X, Y>(IEnumerable)
Take 6 elements of type T, U, V, W, X and Y
public static (T?, U?, V?, W?, X?, Y?) Take<T, U, V, W, X, Y>(this IEnumerable source)
Parameters
sourceIEnumerable
Returns
- (T, U, V, W, X, Y)
Type Parameters
TUVWXY
ThenConcat<T>(T, IEnumerable<T>)
Convert the element to an IEnumerable of the same type and concatinate the specified enumerable on that element.
public static IEnumerable<T> ThenConcat<T>(this T element, IEnumerable<T> then)
Parameters
elementTthenIEnumerable<T>
Returns
- IEnumerable<T>
Type Parameters
T
TryConsume(IEnumerator, out object)
Try to consume the next element from the enumerator.
public static bool TryConsume(this IEnumerator source, out object value)
Parameters
sourceIEnumeratorvalueobject
Returns
WhereAs<T>(IEnumerable)
Convert each element to the type T and return a new enumerable with elements that could be converted to T.
public static IEnumerable<T> WhereAs<T>(this IEnumerable enumerable)
Parameters
enumerableIEnumerable
Returns
- IEnumerable<T>
Type Parameters
T
WithIndex<T>(IEnumerable<T>)
Append indexes to the enumerable and return a new enumerable with those elements.
public static IEnumerable<(T value, int index)> WithIndex<T>(this IEnumerable<T> values)
Parameters
valuesIEnumerable<T>
Returns
- IEnumerable<(T value, int index)>
Type Parameters
T