Table of Contents

Class CollectionExtensions

Namespace
Gamelogic.Extensions.Algorithms
Assembly
Gamelogic.Extensions.dll

This class provides useful extension methods for collections, mostly IEnumerable.

[Version(1, 0, 0)]
public static class CollectionExtensions
Inheritance
CollectionExtensions
Inherited Members

Methods

AddRange<T>(ICollection<T>, IEnumerable<T>)

Add all elements of other to the given source.

Aggregate<T>(IEnumerable<T>, Func<T, T, T>, Func<T, T, T>)

Aggregates the source collection using two different aggregation functions.

AreSequencesEqual<T>(IEnumerable<T>, IEnumerable<T>)

Checks whether the sequences are equal.

AsCountable<T>(IEnumerable<T>)

Converts the source to an IReadOnlyCollection<T>.

AsList<T>(IEnumerable<T>)

Converts the source to an IReadOnlyList<T>.

BinarySearch<TCollection, TElement>(ICollection<TCollection>, TElement, Func<TCollection, TElement>)

Find an element in a collection by binary searching. This requires the collection to be sorted on the values returned by getSubElement This will compare some derived property of the elements in the collection, rather than the elements themselves.

BinarySearch<TCollection, TElement>(ICollection<TCollection>, TElement, Func<TCollection, TElement>, IComparer<TElement>)

Find an element in a collection by binary searching. This requires the collection to be sorted on the values returned by getSubElement This will compare some derived property of the elements in the collection, rather than the elements themselves.

BinarySearch<TCollection, TElement>(ICollection<TCollection>, TElement, Func<TCollection, TElement>, int, int)

Find an element in a collection by binary searching. This requires the collection to be sorted on the values returned by getSubElement This will compare some derived property of the elements in the collection, rather than the elements themselves.

BinarySearch<TCollection, TElement>(ICollection<TCollection>, TElement, Func<TCollection, TElement>, int, int, IComparer<TElement>)

Find an element in a collection by binary searching. This requires the collection to be sorted on the values returned by getSubElement This will compare some derived property of the elements in the collection, rather than the elements themselves.

ButFirst<T>(IEnumerable<T>)

Returns an enumerable of all elements of the given list but the first, keeping them in order.

ButLast<T>(IEnumerable<T>)

Returns an enumerable of all elements in the given list but the last, keeping them in order.

FilterByType<T, TFilter>(IEnumerable<T>)

Returns all elements of the source which are of FilterType.

HasSameElementsAs<T>(IEnumerable<T>, IEnumerable<T>)

Checks if two lists have the same elements, regardless of their order.

IsEmpty<T>(ICollection<T>)

Returns whether this source is empty.

ListToString<T>(IEnumerable<T>)

Returns a pretty string representation of the given list. The resulting string looks something like [a, b, c].

MaxBy<T>(IEnumerable<T>, Func<T, IComparable>)

Finds the maximum element in the source as scored by the given function.

MaxBy<TSource, TKey>(IEnumerable<TSource>, Func<TSource, TKey>)

Finds the minimum element in the source as scored by its projection.

MaxBy<TSource, TKey>(IEnumerable<TSource>, Func<TSource, TKey>, IComparer<TKey>)

Finds the minimum element in the source as scored by the given function applied to a projection on the elements.

MinBy<TSource, TKey>(IEnumerable<TSource>, Func<TSource, TKey>)

Finds the minimum element in the source as scored by its projection.

MinBy<TSource, TKey>(IEnumerable<TSource>, Func<TSource, TKey>, IComparer<TKey>)

Finds the minimum element in the source as scored by the given function applied to a projection on the elements.

MinMax(IEnumerable<int>)

Finds the minimum and maximum values in a collection of integers.

MinMax(IEnumerable<float>)

Finds the minimum and maximum values in a collection of floats.

RandomItem<T>(IEnumerable<T>)

Returns a random element from a source.

RandomItem<T>(IEnumerable<T>, IRandom)

Returns a random element from a source.

RemoveAllBut<T>(List<T>, Predicate<T>)

Removes all the elements in the list that does not satisfy the predicate.

RotateLeft<T>(IEnumerable<T>)

Returns an enumerable with elements in order, but the first element is moved to the end.

RotateRight<T>(IEnumerable<T>)

Returns an enumerable with elements in order, but the last element is moved to the front.

SampleRandom<T>(IEnumerable<T>, int)

Returns a random sample from a source.

SampleRandom<T>(IEnumerable<T>, int, IRandom)

Returns a random sample from a source.

Shuffle<T>(IList<T>)

Shuffles a list.

Shuffle<T>(IList<T>, IRandom)

Shuffles a list.

TakeHalf<T>(IEnumerable<T>)

Returns the first half of elements from a source.

TakeLast<T>(IEnumerable<T>, int)

Returns the last n elements from a source.

TryFirst<T>(IEnumerable<T>, Func<T, bool>, out T)
TryFirst<T>(IEnumerable<T>, out T)
TryLast<T>(IEnumerable<T>, Func<T, bool>, out T)
TryLast<T>(IEnumerable<T>, out T)