Table of Contents

Class LinqExtensions

Namespace
CriusNyx.Util
Assembly
CriusNyxUtil.dll

Extensions for sets and lists.

public static class LinqExtensions
Inheritance
LinqExtensions
Inherited Members

Methods

AddAndTake<T>(IList<T>, T)

Add the new element to the list and return the new element.

public static T AddAndTake<T>(this IList<T> list, T value)

Parameters

list IList<T>
value T

Returns

T

Type Parameters

T

AddAndTake<T>(ISet<T>, T)

Add a new element to the set and return the new element. Throws if the element already exists in the set.

public static T AddAndTake<T>(this ISet<T> set, T value)

Parameters

set ISet<T>
value T

Returns

T

Type Parameters

T

AddAndTake<T, U>(IDictionary<T, U>, T, U)

Add the new element to the dictionary and return the new element. Throws if the element already exists in the dictionary.

public static U AddAndTake<T, U>(this IDictionary<T, U> dict, T key, U value)

Parameters

dict IDictionary<T, U>
key T
value U

Returns

U

Type Parameters

T
U

AddOrGet<T, U>(IDictionary<T, U>, T, Func<U>)

Add the new element to the dictionary, or create a new element and add it to the dictionary.

public static U AddOrGet<T, U>(this IDictionary<T, U> dict, T key, Func<U> generator)

Parameters

dict IDictionary<T, U>
key T
generator Func<U>

Returns

U

Type Parameters

T
U

AddOrGet<T, U>(IDictionary<T, U>, T, U)

Add the new element to the dictionary, or get the element that already exists in the dictionary. Return the new element.

public static U AddOrGet<T, U>(this IDictionary<T, U> dict, T key, U value)

Parameters

dict IDictionary<T, U>
key T
value U

Returns

U

Type Parameters

T
U

AsArray<T>(T)

Convert a single element into an array with that element.

public static T[] AsArray<T>(this T element)

Parameters

element T

Returns

T[]

Type Parameters

T

Consume(IEnumerator)

Consume a single element from the enumerator.

public static object? Consume(this IEnumerator source)

Parameters

source IEnumerator

Returns

object

The next element from the enumerator.

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

source IEnumerator
defaultValue T

Returns

T

The next element from the enumerator.

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

source T[]
other IEnumerable<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

enumerable IEnumerable<T>
action Action<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

dictionary Dictionary<Key, Value>
key Key
create Func<Value>

Returns

Value

Type Parameters

Key
Value

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

left IEnumerable<T>
right IEnumerable<U>

Returns

IEnumerable<(T left, U right)>

Type Parameters

T
U

MatchStart<T>(IEnumerable<T>, params Func<T, bool>[])

Returns true if every provided predicate matches the coresponding list elements, ignoring elements without provided predicates.

public static bool MatchStart<T>(this IEnumerable<T> list, params Func<T, bool>[] predicates)

Parameters

list IEnumerable<T>
predicates Func<T, bool>[]

Returns

bool

True if every predicate matches.

Type Parameters

T

Match<T>(IEnumerable<T>, params Func<T, bool>[])

Returns true if every predicate matches every coresponding list element.

public static bool Match<T>(this IEnumerable<T> list, params Func<T, bool>[] predicates)

Parameters

list IEnumerable<T>
predicates Func<T, bool>[]

Returns

bool

True if every predicate matches.

Type Parameters

T

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

left IEnumerable<T>
right IEnumerable<U>
defaultLeft T
defaultRight U

Returns

IEnumerable<(T left, U right)>

Type Parameters

T
U

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

values IEnumerable<T>
length int
element T

Returns

IEnumerable<T>

Type Parameters

T

ReplaceAndTake<T, U>(Dictionary<T, U>, T, U)

Replace the value in the dictionary and return the new value.

public static U ReplaceAndTake<T, U>(this Dictionary<T, U> dict, T key, U value)

Parameters

dict Dictionary<T, U>
key T
value U

Returns

U

Type Parameters

T
U

Take2<T>(IEnumerable<T>)

Take 2 elements from the source.

public static (T?, T?) Take2<T>(this IEnumerable<T> source)

Parameters

source IEnumerable<T>

Returns

(T, T)

Type Parameters

T

Take3<T>(IEnumerable<T>)

Take 3 elements from the source.

public static (T?, T?, T?) Take3<T>(this IEnumerable<T> source)

Parameters

source IEnumerable<T>

Returns

(T, T, T)

Type Parameters

T

Take4<T>(IEnumerable<T>)

Take 4 elements from the source.

public static (T?, T?, T?, T?) Take4<T>(this IEnumerable<T> source)

Parameters

source IEnumerable<T>

Returns

(T, T, T, T)

Type Parameters

T

Take5<T>(IEnumerable<T>)

Take 5 elements from the source.

public static (T?, T?, T?, T?, T?) Take5<T>(this IEnumerable<T> source)

Parameters

source IEnumerable<T>

Returns

(T, T, T, T, T)

Type Parameters

T

Take6<T>(IEnumerable<T>)

Take 6 elements from the source.

public static (T?, T?, T?, T?, T?, T?) Take6<T>(this IEnumerable<T> source)

Parameters

source IEnumerable<T>

Returns

(T, T, T, T, T, 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

source IEnumerable

Returns

(T, U)

Type Parameters

T
U

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

source IEnumerable

Returns

(T, U, V)

Type Parameters

T
U
V

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

source IEnumerable

Returns

(T, U, V, W)

Type Parameters

T
U
V
W

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

source IEnumerable

Returns

(T, U, V, W, X)

Type Parameters

T
U
V
W
X

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

source IEnumerable

Returns

(T, U, V, W, X, Y)

Type Parameters

T
U
V
W
X
Y

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

element T
then IEnumerable<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

source IEnumerator
value object

Returns

bool

True if there is an element in the enumerator.

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

enumerable IEnumerable

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

values IEnumerable<T>

Returns

IEnumerable<(T value, int index)>

Type Parameters

T