|
static void | ForEach< T > (this IEnumerable< T > collection, Action< T > toRun) |
| The missing ForEach method.
|
static void | JoinAll (this IEnumerable< Thread > threads) |
| call Thread.Join for each thread in the collection
|
static void | ForEach< T > (this IEnumerable< T > collection, Action< T, int > toRunWithIndex) |
| The missing ForEach method - synchronous variant which also provides the current item index.
|
static T | FindOrAdd< T > (this ICollection< T > collection, T seek) |
| Find or add an item to a collection.
|
static T | FindOrAdd< T > (this ICollection< T > collection, Func< T, bool > matcher) |
| Find or add an item to a collection.
|
static T | FindOrAdd< T > (this ICollection< T > collection, Func< T, bool > matcher, Func< T > generator) |
| Find or add an item to a collection.
|
static bool | IsSameAs< T > (this IEnumerable< T > collection, IEnumerable< T > otherCollection) |
| Calculates if two collections hold the same items, irrespective of order.
|
static string | JoinWith< T > (this IEnumerable< T > collection, string joinWith) |
| Fluent alternative to string.Join()
|
static string | JoinWith< T > (this IEnumerable< T > collection, char joinWith) |
| Fluent alternative to string.Join()
|
static bool | IsEmpty< T > (this IEnumerable< T > collection) |
| Convenience method, essentially opposite to Any(), except that it also handles null collections.
|
static IEnumerable< T > | EmptyIfNull< T > (this IEnumerable< T > collection) |
| Convenience method to mitigate null checking and errors when a null collection can be treated as if it were empty, eg: someCollection.EmptyIfNull().ForEach(DoSomething);.
|
static T[] | And< T > (this IEnumerable< T > source, params T[] values) |
| Convenience method to create a new array with the provided element(s) appended.
|
static T[] | And< T > (this IEnumerable< T > source, IEnumerable< T > values) |
| Convenience method to create a new array with the provided element(s) appended.
|
static T[] | And< T > (this T[] source, params T[] values) |
| Convenience method to create a new array with the provided element(s) appended.
|
static T[] | And< T > (this T[] source, IEnumerable< T > values) |
| Convenience method to create a new array with the provided element(s) appended.
|
static List< T > | And< T > (this List< T > source, params T[] values) |
| Convenience method to add one one or more values to a list.
|
static IList< T > | And< T > (this IList< T > source, params T[] values) |
| Convenience method to add more values to a list.
|
static T[] | ButNot< T > (this IEnumerable< T > source, params T[] toRemove) |
| Convenience / fluent method to provide an array without the provided item(s)
|
static IEnumerable< T > | Flatten< T > (this IEnumerable< IEnumerable< T > > collection) |
| Convenience wrapper around SelectMany; essentially flattens a nested collection of collection(s) of some item. Exactly equivalent to: collection.SelectMany(o => o);.
|
static IEnumerable< TResult > | SelectNonNull< TCollection, TResult > (this IEnumerable< TCollection > collection, Func< TCollection, TResult?> grabber) |
| Convenience method to get the results of a selection where the results are non-null -> this variant works on Nullable types.
|
static IEnumerable< TResult > | SelectNonNull< TCollection, TResult > (this IEnumerable< TCollection > collection, Func< TCollection, TResult > grabber) |
| Convenience method to get the results of a selection where the results are non-null -> this variant works on types which can natively hold the value null.
|
static string | AsText< T > (this IEnumerable< T > input, string delimiter=null) |
| Convenience method to produce a block of text from a collection of items -> optionally, delimit with a string of your choice instead of a newline -> essentially a wrapper around JoinWith()
|
static string | AsTextList< T > (this IEnumerable< T > input) |
| Easy way to produce a text list from a collection of items, eg [ "cat", "dog", "cow" ] becomes.
|
static string | AsTextList< T > (this IEnumerable< T > input, string itemMarker) |
| Easy way to produce a text list from a collection of items with a provided item marker, eg if the item marker is '* ' [ "cat", "dog", "cow" ] becomes.
|
static string | AsTextList< T > (this IEnumerable< T > input, string itemMarker, string whenEmpty) |
| Easy way to produce a text list from a collection of items with a provided item marker, eg if the item marker is '* ' [ "cat", "dog", "cow" ] becomes.
|
static string | AsTextListWithHeader< T > (this IEnumerable< T > input, string header) |
| Produces a text list from the input, with the provided header and item marker, or returns whenEmpty when nothing in the input, eg, given the collection [ "flower", "hat", "pen" ] and heading "inventory:": inventory:
|
static string | AsTextListWithHeader< T > (this IEnumerable< T > input, string header, string itemMarker) |
| Produces a text list from the input, with the provided header and item marker, or returns whenEmpty when nothing in the input, eg, given the collection [ "flower", "hat", "pen" ] and heading "inventory:": inventory:
|
static string | AsTextListWithHeader< T > (this IEnumerable< T > input, string header, string itemMarker, string whenEmpty) |
| Produces a text list from the input, with the provided header and item marker, or returns whenEmpty when nothing in the input, eg, given the collection [ "flower", "hat", "pen" ] and heading "inventory:": inventory:
|
static bool | HasUnique< T > (this IEnumerable< T > input, Func< T, bool > matcher) |
| Convenience method to test if a collection has a single item matching the provided matcher function.
|
static void | TimesDo (this int howMany, Action toRun) |
| Fluency method to run an action a certain number of times, eg: 10.TimesDo(() => Console.WriteLine("Hello World"));.
|
static void | TimesDo (this int howMany, Action< int > toRun) |
| Fluency method to run an action a certain number of times. This variant runs on an action given the current index at each run, eg: 10.TimesDo(i => Console.WriteLine($"This action has run {i} times"));.
|
static T | Second< T > (this IEnumerable< T > src) |
| Convenience method to get the second item from a collection.
|
static T | Third< T > (this IEnumerable< T > src) |
| Convenience method to get the third item from a collection.
|
static T | Fourth< T > (this IEnumerable< T > src) |
| Convenience method to get the fourth item from a collection.
|
static T | Nth< T > (this IEnumerable< T > src, int n) |
| Convenience method to get the Nth item from a collection.
|
static T | At< T > (this IEnumerable< T > src, int n) |
| Alias for Nth.
|
static T | FirstAfter< T > (this IEnumerable< T > src, int toSkip) |
| Convenience method to get the first item after skipping N items from a collection -> equivalent to collection.Skip(N).First(); -> collection.FirstAfter(2) returns the 3rd element.
|
static T | FirstOrDefaultAfter< T > (this IEnumerable< T > src, int toSkip) |
| Convenience method to get the first item after skipping N items from a collection -> equivalent to collection.Skip(N).First(); -> collection.FirstAfter(2) returns the 3rd element -> this variant returns the default value for T if the N is out of bounds.
|
static IEnumerable< TItem > | FindDuplicates< TItem > (this IEnumerable< TItem > src) |
| Find duplicates within a collection according to a provided discriminator.
|
static IEnumerable< DuplicateResult< TKey, TItem > > | FindDuplicates< TItem, TKey > (this IEnumerable< TItem > src, Func< TItem, TKey > discriminator) |
| Find duplicates within a collection according to a provided discriminator.
|
static bool | None< T > (this IEnumerable< T > collection) |
| Inverse of All() LINQ method: test should return false for all elements.
|
static bool | None< T > (this IEnumerable< T > collection, Func< T, bool > test) |
| Inverse of All() LINQ method: test should return false for all elements.
|
static T[] | AsArray< T > (this IEnumerable< T > collection) |
| Provides an array for the collection, to avoid the potential for multiple enumeration on an IEnumerable<T> argument to a method.
|
static IEnumerable< TOther > | ImplicitCast< TOther > (this IEnumerable collection) |
| Performs implicit casting on a collection -> just like .Cast<T>, this will explode if the cast cannot succeed. C'est la vie.
|
static IEnumerable< Tuple< TLeft, TRight > > | StrictZip< TLeft, TRight > (this IEnumerable< TLeft > left, IEnumerable< TRight > right) |
| Similar to LINQ's Zip extension method, this will zip two enumerables together using yield.
|
static IEnumerable< TResult > | StrictZip< TLeft, TRight, TResult > (this IEnumerable< TLeft > left, IEnumerable< TRight > right, Func< TLeft, TRight, TResult > generator) |
| Similar to LINQ's Zip extension method, this will zip two enumerables together using yield.
|
static bool | Matches< T > (this IEnumerable< T > left, IEnumerable< T > right) |
| Performs full-collection matching on two collections of the same type, assuming that .Equals() is a valid comparator between two objects of type T.
|
static bool | Matches< T > (this IEnumerable< T > left, IEnumerable< T > right, Func< T, T, bool > comparer) |
| Performs matching on collections of the same type.
|
static bool | CrossMatches< TLeft, TRight > (this IEnumerable< TLeft > left, IEnumerable< TRight > right, Func< TLeft, TRight, bool > comparer) |
| Performs cross-type matching on collections.
|
static IEnumerable< string > | Trim (this IEnumerable< string > source) |
| Returns the original collection of strings trimmed.
|
static IEnumerable< string > | TrimStart (this IEnumerable< string > source) |
| Returns the original collection of strings trimmed at the start.
|
static IEnumerable< string > | TrimEnd (this IEnumerable< string > source) |
| Returns the original collection of strings trimmed at the start.
|
static IEnumerable< string > | PadLeft< T > (this IEnumerable< T > source) |
| Returns a copy of the input strings where all are padded to the left with spaces to fit to the longest item in the collection.
|
static IEnumerable< string > | PadLeft< T > (this IEnumerable< T > source, char padWith) |
| Returns a copy of the input strings where all are padded to the left with the padWith char to fit to the longest item in the collection.
|
static IEnumerable< string > | PadLeft< T > (this IEnumerable< T > source, int requiredLength) |
| Returns a copy of the input strings where all are padded to the left to the provided required length with spaces.
|
static IEnumerable< string > | PadLeft< T > (this IEnumerable< T > source, int requiredLength, char padWith) |
| Returns a copy of the input strings where all are padded to the left to the provided required length with the provided padWith character.
|
static IEnumerable< string > | PadRight< T > (this IEnumerable< T > source) |
| Returns a copy of the input strings where all are padded to the right with spaces to fit to the longest item in the collection.
|
static IEnumerable< string > | PadRight< T > (this IEnumerable< T > source, char padWith) |
| Returns a copy of the input strings where all are padded to the right with the padWith char to fit to the longest item in the collection.
|
static IEnumerable< string > | PadRight< T > (this IEnumerable< T > source, int requiredLength) |
| Returns a copy of the input strings where all are padded to the right with spaces char to fit to the requiredLength.
|
static IEnumerable< string > | PadRight< T > (this IEnumerable< T > source, int requiredLength, char padWith) |
| Returns a copy of the input strings where all are padded to the right with the padWith char to fit to the requiredLength.
|
static bool | IsEqualTo< T > (this IEnumerable< T > left, IEnumerable< T > right) |
| Compares two collections and returns true if they have exactly the same values in the same order.
|
static bool | IsEquivalentTo< T > (this IEnumerable< T > left, IEnumerable< T > right) |
| Compares two collections and returns true if they have exactly the same values in any order.
|
static HashSet< T > | AsHashSet< T > (this IEnumerable< T > collection) |
| Produces an hashset from a collection -> shorthand for new HashSet<T>(collection)
|
static HashSet< T > | ToHashSet< T > (this IEnumerable< T > collection) |
| OBSOLETE - please use AsHashSet as ToHashSet is now implemented in the latest System.Linq.
|
static TResult[] | Map< TResult, TSource > (this IEnumerable< TSource > collection, Func< TSource, TResult > transform) |
| null-safe shorthand for .Select(...).ToArray()
|
static IList< TResult > | MapList< TResult, TSource > (this IEnumerable< TSource > collection, Func< TSource, TResult > transform) |
| null-safe shorthand for .Select(...).ToList()
|
static T[] | Filter< T > (this IEnumerable< T > collection, Func< T, bool > filter) |
| null-safe shorthand for .Where(...).ToArray()
|
static IList< T > | FilterList< T > (this IEnumerable< T > collection, Func< T, bool > filter) |
| null-safe shorthand for .Where(...).ToList()
|
static IEnumerable< T > | FindRepeatedValues< T > (this IEnumerable< T > collection) |
| Find singular occurrences of repeated values within a collection.
|
static IEnumerable< T > | FindAllRepeatedValues< T > (this IEnumerable< T > collection) |
| Find all occurrences of repeated values within a collection. All repeated values are returned, eg: [ 1, 1, 1 ] => [ 1, 1 ].
|
static IEnumerable< T > | FindUniqueValues< T > (this IEnumerable< T > collection) |
| Finds all unique (non-repeated) values within a collection.
|
static string | JoinPath (this IEnumerable< string > parts) |
| Join the parts into a path for the current platform.
|
static string | JoinPath (this IEnumerable< string > parts, PathType pathType) |
| Join the parts into a path for the specified platform.
|
static T[] | FilterNulls< T > (this T?[] collection) |
| Filters out null values in a collection of nullable values and return non-nullable values.
|
static IEnumerable< T > | FilterNulls< T > (this IEnumerable< T?> collection) |
| Filters out null values in a collection of nullable values and return non-nullable values. Lazily evaluated so large streams are ok, but the flip side is you should .ToArray() when you have a small collection and want to be sure of not re-enumerating.
|
static T[] | FilterNulls< T > (this T[] collection) |
| Filters out null values in a collection of nullable values and return non-nullable values.
|
static IEnumerable< T > | FilterNulls< T > (this IEnumerable< T > collection) |
| Filters out null values in a collection of nullable values and return non-nullable values. Lazily evaluated so large streams are ok, but the flip side is you should .ToArray() when you have a small collection and want to be sure of not re-enumerating.
|
static bool | IsIn< T > (this T needle, T haystack, params T[] moreHaystack) |
| tests if the needle is one of the provided items (convenience params variant)
|
static bool | IsIn< T > (this T needle, IEnumerable< T > haystack) |
| tests if the needle is in the haystack
|
static bool | IsIn< T > (this T needle, IEnumerable< T > haystack, IEqualityComparer< T > equalityComparer) |
| tests if the needle is in the haystack, using the provided equality comparer
|
static TCollection | AddRange< TCollection, TItem > (this TCollection collection, IEnumerable< TItem > toAdd) |
| Augments collections which don't have an AddRange method with one that does the trick.
|
static TCollection | AddRange< TCollection, TItem > (this TCollection collection, params TItem[] items) |
| Augments collections with an AddRange(...) that takes params items.
|
static T | Seek< T > (this IEnumerable data) |
| Find the first item of the specified type in the collection.
|
static T | Seek< T > (this IEnumerable data, int skip) |
| Find the first item of the specified type in the collection, skipping the first N elements of that type.
|
static T | Seek< T > (this IEnumerable data, int skip, Func< T, bool > predicate) |
| Find the first element of the specified type, which matches the predicate, after skipping the provided number of matches. This would allow you to find subsequent matches, eg: var result1 = collection.Find<MyType>>(); var result2 = collection.Find<MyType>>(1); // etc.
|
static T | Seek< T > (this IEnumerable data, Func< T, bool > predicate) |
| Finds the first element of the specified type, matching the provided predicate, or throws an exception.
|
static T | SeekOrDefault< T > (this IEnumerable data) |
| Finds the first item of the specified type or returns the default value for T.
|
static T | SeekOrDefault< T > (this IEnumerable data, int skip) |
| Finds the first item of the specified type or returns the default value for T, after skipping N matches.
|
static T | SeekOrDefault< T > (this IEnumerable data, Func< T, bool > predicate) |
| Finds the first matching item of the specified type or returns the default value for T, after skipping N matches.
|
static T | SeekOrDefault< T > (this IEnumerable data, int skip, Func< T, bool > predicate) |
| Finds the first match of the specified type or returns the default value for T, after skipping N matches.
|
static bool | ContainsAllOf< T > (this IEnumerable< T > collection, params T[] values) |
| Returns true if the collection contains ALL of the provided values.
|
static bool | ContainsAnyOf< T > (this IEnumerable< T > collection, params T[] values) |
| Returns true if the collection contains ANY of the provided values.
|
static bool | ContainsAnyOf< T > (this IEnumerable< T > collection, IEnumerable< T > values) |
| Returns true if the collection contains ANY of the provided values.
|
static IDictionary< T, int > | AsFrequencyDistribution< T > (this IEnumerable< T > collection) |
| Given a collection of items, produces a dictionary where the keys are the unique items and the values are counts of those items, eg counting fruit:
|
static IDictionary< T, int > | AsFrequencyDistribution< T > (this IEnumerable< T > collection, T nullKey) |
| Given a collection of items, produces a dictionary where the keys are the unique items and the values are counts of those items, eg counting fruit:
|