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

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

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

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

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

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

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