PeanutButter
Loading...
Searching...
No Matches
PeanutButter.Utils.ExtensionsForIEnumerables Class Reference

Useful extensions for IEnumerable<T> collections. More...

Classes

class  DuplicateResult< TKey, TItem >
 DTO for conveying results from the more complex FindDuplicates variant which includes a key discriminator. More...

Static Public Member Functions

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:

Detailed Description

Useful extensions for IEnumerable<T> collections.

Member Function Documentation

◆ AddRange< TCollection, TItem >() [1/2]

TCollection PeanutButter.Utils.ExtensionsForIEnumerables.AddRange< TCollection, TItem > ( this TCollection collection,
IEnumerable< TItem > toAdd )
static

Augments collections which don't have an AddRange method with one that does the trick.

Parameters
collection
toAdd
Template Parameters
TCollection
TItem
Returns
Type Constraints
TCollection :ICollection<TItem> 

◆ AddRange< TCollection, TItem >() [2/2]

TCollection PeanutButter.Utils.ExtensionsForIEnumerables.AddRange< TCollection, TItem > ( this TCollection collection,
params TItem[] items )
static

Augments collections with an AddRange(...) that takes params items.

Parameters
collection
items
Template Parameters
TCollection
TItem
Returns
Type Constraints
TCollection :ICollection<TItem> 

◆ And< T >() [1/6]

T[] PeanutButter.Utils.ExtensionsForIEnumerables.And< T > ( this IEnumerable< T > source,
IEnumerable< T > values )
static

Convenience method to create a new array with the provided element(s) appended.

Parameters
sourceSource array to start with
values
Template Parameters
TItem type of the array
Returns
A new array which is the source with the new items appended

◆ And< T >() [2/6]

T[] PeanutButter.Utils.ExtensionsForIEnumerables.And< T > ( this IEnumerable< T > source,
params T[] values )
static

Convenience method to create a new array with the provided element(s) appended.

Parameters
sourceSource array to start with
values
Template Parameters
TItem type of the array
Returns
A new array which is the source with the new items appended

◆ And< T >() [3/6]

IList< T > PeanutButter.Utils.ExtensionsForIEnumerables.And< T > ( this IList< T > source,
params T[] values )
static

Convenience method to add more values to a list.

Parameters
source
values
Template Parameters
T
Returns

◆ And< T >() [4/6]

List< T > PeanutButter.Utils.ExtensionsForIEnumerables.And< T > ( this List< T > source,
params T[] values )
static

Convenience method to add one one or more values to a list.

Parameters
source
values
Template Parameters
T
Returns

◆ And< T >() [5/6]

T[] PeanutButter.Utils.ExtensionsForIEnumerables.And< T > ( this T[] source,
IEnumerable< T > values )
static

Convenience method to create a new array with the provided element(s) appended.

Parameters
sourceSource array to start with
values
Template Parameters
TItem type of the array
Returns
A new array which is the source with the new items appended

◆ And< T >() [6/6]

T[] PeanutButter.Utils.ExtensionsForIEnumerables.And< T > ( this T[] source,
params T[] values )
static

Convenience method to create a new array with the provided element(s) appended.

Parameters
sourceSource array to start with
values
Template Parameters
TItem type of the array
Returns
A new array which is the source with the new items appended

◆ AsArray< T >()

T[] PeanutButter.Utils.ExtensionsForIEnumerables.AsArray< T > ( this IEnumerable< T > collection)
static

Provides an array for the collection, to avoid the potential for multiple enumeration on an IEnumerable<T> argument to a method.

  • given an array, returns the exact array
  • given null, returns empty array
  • given any other IEnumerable<T>, calls .ToArray on it
Parameters
collection
Template Parameters
T
Returns

◆ AsFrequencyDistribution< T >() [1/2]

IDictionary< T, int > PeanutButter.Utils.ExtensionsForIEnumerables.AsFrequencyDistribution< T > ( this IEnumerable< T > collection)
static

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:

  • apple
  • pear
  • apple
  • orange
  • pear
  • kiwi
  • pear we'd get a collection of: { ["apple"] = 2, ["pear"] = 3, ["orange"] = 1, ["kiwi"] = 1 } null values are not counted unless you provide a key to use for the null case in the overload accepting such
Parameters
collection
Template Parameters
T
Returns

◆ AsFrequencyDistribution< T >() [2/2]

IDictionary< T, int > PeanutButter.Utils.ExtensionsForIEnumerables.AsFrequencyDistribution< T > ( this IEnumerable< T > collection,
T nullKey )
static

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:

  • apple
  • pear
  • apple
  • orange
  • pear
  • kiwi
  • pear we'd get a collection of: { ["apple"] = 2, ["pear"] = 3, ["orange"] = 1, ["kiwi"] = 1 }
Parameters
collection
nullKeyWhen a null value is encountered in the source collection, use this key. If the null key is null then null values will not be counted
Template Parameters
T
Returns

◆ AsHashSet< T >()

HashSet< T > PeanutButter.Utils.ExtensionsForIEnumerables.AsHashSet< T > ( this IEnumerable< T > collection)
static

Produces an hashset from a collection -> shorthand for new HashSet<T>(collection)

Parameters
collection
Template Parameters
T
Returns

◆ AsText< T >()

string PeanutButter.Utils.ExtensionsForIEnumerables.AsText< T > ( this IEnumerable< T > input,
string delimiter = null )
static

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()

Parameters
inputSource input lines
delimiterOptional delimiter (default is Environment.NewLine)
Template Parameters
TItem type of collection
Returns
String representation of the the items

◆ AsTextList< T >() [1/3]

string PeanutButter.Utils.ExtensionsForIEnumerables.AsTextList< T > ( this IEnumerable< T > input)
static

Easy way to produce a text list from a collection of items, eg [ "cat", "dog", "cow" ] becomes.

  • cat
  • dog
  • cow
Parameters
input
Template Parameters
T
Returns

◆ AsTextList< T >() [2/3]

string PeanutButter.Utils.ExtensionsForIEnumerables.AsTextList< T > ( this IEnumerable< T > input,
string itemMarker )
static

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.

  • cat
  • dog
  • cow
Parameters
input
itemMarker
Template Parameters
T
Returns

◆ AsTextList< T >() [3/3]

string PeanutButter.Utils.ExtensionsForIEnumerables.AsTextList< T > ( this IEnumerable< T > input,
string itemMarker,
string whenEmpty )
static

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.

  • cat
  • dog
  • cow
Parameters
input
itemMarker
whenEmptyReturns this string when the collection is empty
Template Parameters
T
Returns

◆ AsTextListWithHeader< T >() [1/3]

string PeanutButter.Utils.ExtensionsForIEnumerables.AsTextListWithHeader< T > ( this IEnumerable< T > input,
string header )
static

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:

  • flower
  • hat
  • pen
Parameters
input
header
Template Parameters
T
Returns

◆ AsTextListWithHeader< T >() [2/3]

string PeanutButter.Utils.ExtensionsForIEnumerables.AsTextListWithHeader< T > ( this IEnumerable< T > input,
string header,
string itemMarker )
static

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:

  • flower
  • hat
  • pen
Parameters
input
header
itemMarker
Template Parameters
T
Returns

◆ AsTextListWithHeader< T >() [3/3]

string PeanutButter.Utils.ExtensionsForIEnumerables.AsTextListWithHeader< T > ( this IEnumerable< T > input,
string header,
string itemMarker,
string whenEmpty )
static

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:

  • flower
  • hat
  • pen
Parameters
input
header
itemMarker
whenEmpty
Template Parameters
T
Returns

◆ At< T >()

T PeanutButter.Utils.ExtensionsForIEnumerables.At< T > ( this IEnumerable< T > src,
int n )
static

Alias for Nth.

Parameters
srcSource collection
nZero-based index into collection
Template Parameters
T
Returns

◆ ButNot< T >()

T[] PeanutButter.Utils.ExtensionsForIEnumerables.ButNot< T > ( this IEnumerable< T > source,
params T[] toRemove )
static

Convenience / fluent method to provide an array without the provided item(s)

Parameters
sourceSource collection
toRemoveitems which should not appear in the result array
Template Parameters
TItem type of the array
Returns
A new array of T with the specified items not present

◆ ContainsAllOf< T >()

bool PeanutButter.Utils.ExtensionsForIEnumerables.ContainsAllOf< T > ( this IEnumerable< T > collection,
params T[] values )
static

Returns true if the collection contains ALL of the provided values.

Parameters
collection
values
Template Parameters
T
Returns

◆ ContainsAnyOf< T >() [1/2]

bool PeanutButter.Utils.ExtensionsForIEnumerables.ContainsAnyOf< T > ( this IEnumerable< T > collection,
IEnumerable< T > values )
static

Returns true if the collection contains ANY of the provided values.

Parameters
collection
values
Template Parameters
T
Returns

◆ ContainsAnyOf< T >() [2/2]

bool PeanutButter.Utils.ExtensionsForIEnumerables.ContainsAnyOf< T > ( this IEnumerable< T > collection,
params T[] values )
static

Returns true if the collection contains ANY of the provided values.

Parameters
collection
values
Template Parameters
T
Returns

◆ CrossMatches< TLeft, TRight >()

bool PeanutButter.Utils.ExtensionsForIEnumerables.CrossMatches< TLeft, TRight > ( this IEnumerable< TLeft > left,
IEnumerable< TRight > right,
Func< TLeft, TRight, bool > comparer )
static

Performs cross-type matching on collections.

Parameters
leftleft collection
rightright collection
comparerfunction to compare items
Template Parameters
TLeft
TRight
Returns
true if collections are of the same size and each item, in order, from the left item, matches the right one

◆ EmptyIfNull< T >()

IEnumerable< T > PeanutButter.Utils.ExtensionsForIEnumerables.EmptyIfNull< T > ( this IEnumerable< T > collection)
static

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);.

Parameters
collectionSource collection to operate over
Template Parameters
TItem type of the collection
Returns
An empty collection if the source is null; otherwise the source.

◆ Filter< T >()

T[] PeanutButter.Utils.ExtensionsForIEnumerables.Filter< T > ( this IEnumerable< T > collection,
Func< T, bool > filter )
static

null-safe shorthand for .Where(...).ToArray()

  • will return an empty array for a null input
Parameters
collection
filter
Template Parameters
T
Returns

◆ FilterList< T >()

IList< T > PeanutButter.Utils.ExtensionsForIEnumerables.FilterList< T > ( this IEnumerable< T > collection,
Func< T, bool > filter )
static

null-safe shorthand for .Where(...).ToList()

  • will return an empty list for a null input
Parameters
collection
filter
Template Parameters
T
Returns

◆ FilterNulls< T >() [1/4]

IEnumerable< T > PeanutButter.Utils.ExtensionsForIEnumerables.FilterNulls< T > ( this IEnumerable< T > collection)
static

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.

Parameters
collection
Template Parameters
T
Returns

◆ FilterNulls< T >() [2/4]

IEnumerable< T > PeanutButter.Utils.ExtensionsForIEnumerables.FilterNulls< T > ( this IEnumerable< T?> collection)
static

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.

Parameters
collection
Template Parameters
T
Returns
Type Constraints
T :struct 

◆ FilterNulls< T >() [3/4]

T[] PeanutButter.Utils.ExtensionsForIEnumerables.FilterNulls< T > ( this T?[] collection)
static

Filters out null values in a collection of nullable values and return non-nullable values.

Parameters
collection
Template Parameters
T
Returns
Type Constraints
T :struct 

◆ FilterNulls< T >() [4/4]

T[] PeanutButter.Utils.ExtensionsForIEnumerables.FilterNulls< T > ( this T[] collection)
static

Filters out null values in a collection of nullable values and return non-nullable values.

Parameters
collection
Template Parameters
T
Returns

◆ FindAllRepeatedValues< T >()

IEnumerable< T > PeanutButter.Utils.ExtensionsForIEnumerables.FindAllRepeatedValues< T > ( this IEnumerable< T > collection)
static

Find all occurrences of repeated values within a collection. All repeated values are returned, eg: [ 1, 1, 1 ] => [ 1, 1 ].

Parameters
collection
Template Parameters
T
Returns

◆ FindDuplicates< TItem >()

IEnumerable< TItem > PeanutButter.Utils.ExtensionsForIEnumerables.FindDuplicates< TItem > ( this IEnumerable< TItem > src)
static

Find duplicates within a collection according to a provided discriminator.

Parameters
srcCollection to operate on
Template Parameters
TItemType of items in the collection
Returns
Collection of duplicate items

◆ FindDuplicates< TItem, TKey >()

IEnumerable< DuplicateResult< TKey, TItem > > PeanutButter.Utils.ExtensionsForIEnumerables.FindDuplicates< TItem, TKey > ( this IEnumerable< TItem > src,
Func< TItem, TKey > discriminator )
static

Find duplicates within a collection according to a provided discriminator.

Parameters
srcCollection to operate on
discriminatorFunction to determine uniqueness of each item: should return whatever identifies a particular item uniquely
Template Parameters
TItemType of items in the collection
TKeyType of key used to discriminate items
Returns
Collection of DuplicateResult items which contain duplicates, according to the provided discriminator

◆ FindOrAdd< T >() [1/3]

T PeanutButter.Utils.ExtensionsForIEnumerables.FindOrAdd< T > ( this ICollection< T > collection,
Func< T, bool > matcher )
static

Find or add an item to a collection.

  • item equality is determined by the provided matcher
  • new items are generated with new T()
Parameters
collection
matcher
Template Parameters
T
Returns
Type Constraints
T :new() 

◆ FindOrAdd< T >() [2/3]

T PeanutButter.Utils.ExtensionsForIEnumerables.FindOrAdd< T > ( this ICollection< T > collection,
Func< T, bool > matcher,
Func< T > generator )
static

Find or add an item to a collection.

  • item equality is determined by the provided matcher
  • new items are generated with the provided matcher
Parameters
collection
matcher
generator
Template Parameters
T
Returns
Exceptions
ArgumentNullExceptionThrown if the collection, matcher or generator are null

◆ FindOrAdd< T >() [3/3]

T PeanutButter.Utils.ExtensionsForIEnumerables.FindOrAdd< T > ( this ICollection< T > collection,
T seek )
static

Find or add an item to a collection.

  • item equality is determined by T.Equals
Parameters
collection
seek
Template Parameters
T
Returns

◆ FindRepeatedValues< T >()

IEnumerable< T > PeanutButter.Utils.ExtensionsForIEnumerables.FindRepeatedValues< T > ( this IEnumerable< T > collection)
static

Find singular occurrences of repeated values within a collection.

Parameters
collection
Template Parameters
T
Returns

◆ FindUniqueValues< T >()

IEnumerable< T > PeanutButter.Utils.ExtensionsForIEnumerables.FindUniqueValues< T > ( this IEnumerable< T > collection)
static

Finds all unique (non-repeated) values within a collection.

  • this is not the same as .Distinct(), which finds each distinct value within a set (ie, collapses repeated values)
  • note, this cannot be performed lazily: the entire collection must be read once before a result can be calculated. This method is not suitable for unending streams, and should be used with caution against large streams.
Parameters
collection
Template Parameters
T
Returns

◆ FirstAfter< T >()

T PeanutButter.Utils.ExtensionsForIEnumerables.FirstAfter< T > ( this IEnumerable< T > src,
int toSkip )
static

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.

Parameters
srcSource collection
toSkipHow many items to skip
Template Parameters
TItem type of the collection
Returns
The third item, when available. Will throw if there is no item available.

◆ FirstOrDefaultAfter< T >()

T PeanutButter.Utils.ExtensionsForIEnumerables.FirstOrDefaultAfter< T > ( this IEnumerable< T > src,
int toSkip )
static

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.

Parameters
srcSource collection
toSkipHow many items to skip
Template Parameters
TItem type of the collection
Returns
The third item, when available. Will return the default value for T otherwise.

◆ Flatten< T >()

IEnumerable< T > PeanutButter.Utils.ExtensionsForIEnumerables.Flatten< T > ( this IEnumerable< IEnumerable< T > > collection)
static

Convenience wrapper around SelectMany; essentially flattens a nested collection of collection(s) of some item. Exactly equivalent to: collection.SelectMany(o => o);.

Parameters
collectionSource collection to operate on
Template Parameters
TItem type of the collection
Returns
A new, flat collection

◆ ForEach< T >() [1/2]

void PeanutButter.Utils.ExtensionsForIEnumerables.ForEach< T > ( this IEnumerable< T > collection,
Action< T > toRun )
static

The missing ForEach method.

Parameters
collectionSubject collection to operate over
toRunAction to run on each member of the collection
Template Parameters
TItem type of the collection

◆ ForEach< T >() [2/2]

void PeanutButter.Utils.ExtensionsForIEnumerables.ForEach< T > ( this IEnumerable< T > collection,
Action< T, int > toRunWithIndex )
static

The missing ForEach method - synchronous variant which also provides the current item index.

Parameters
collectionSubject collection to operate over
toRunWithIndexAction to run on each member of the collection
Template Parameters
TItem type of the collection

◆ Fourth< T >()

T PeanutButter.Utils.ExtensionsForIEnumerables.Fourth< T > ( this IEnumerable< T > src)
static

Convenience method to get the fourth item from a collection.

Parameters
srcSource collection
Template Parameters
TItem type of the collection
Returns
The fourth item, when available. Will throw if there is no item available.

◆ HasUnique< T >()

bool PeanutButter.Utils.ExtensionsForIEnumerables.HasUnique< T > ( this IEnumerable< T > input,
Func< T, bool > matcher )
static

Convenience method to test if a collection has a single item matching the provided matcher function.

Parameters
inputSource collection
matcherFunction to run over each item to test if it passes
Template Parameters
TItem type of the collection
Returns
True if only one item in the collection got a true value from the matcher function; false if zero or more than one items were matched.

◆ ImplicitCast< TOther >()

IEnumerable< TOther > PeanutButter.Utils.ExtensionsForIEnumerables.ImplicitCast< TOther > ( this IEnumerable collection)
static

Performs implicit casting on a collection -> just like .Cast<T>, this will explode if the cast cannot succeed. C'est la vie.

Parameters
collection
Template Parameters
TOther
Returns

◆ IsEmpty< T >()

bool PeanutButter.Utils.ExtensionsForIEnumerables.IsEmpty< T > ( this IEnumerable< T > collection)
static

Convenience method, essentially opposite to Any(), except that it also handles null collections.

Parameters
collectionSource collection to operate on
Template Parameters
TItem type of the collection
Returns
True if the collection is null or has no items; false otherwise.

◆ IsEqualTo< T >()

bool PeanutButter.Utils.ExtensionsForIEnumerables.IsEqualTo< T > ( this IEnumerable< T > left,
IEnumerable< T > right )
static

Compares two collections and returns true if they have exactly the same values in the same order.

Parameters
left
right
Template Parameters
T
Returns

◆ IsEquivalentTo< T >()

bool PeanutButter.Utils.ExtensionsForIEnumerables.IsEquivalentTo< T > ( this IEnumerable< T > left,
IEnumerable< T > right )
static

Compares two collections and returns true if they have exactly the same values in any order.

Parameters
left
right
Template Parameters
T
Returns

◆ IsIn< T >() [1/3]

bool PeanutButter.Utils.ExtensionsForIEnumerables.IsIn< T > ( this T needle,
IEnumerable< T > haystack )
static

tests if the needle is in the haystack

Parameters
needle
haystack
Template Parameters
T
Returns

◆ IsIn< T >() [2/3]

bool PeanutButter.Utils.ExtensionsForIEnumerables.IsIn< T > ( this T needle,
IEnumerable< T > haystack,
IEqualityComparer< T > equalityComparer )
static

tests if the needle is in the haystack, using the provided equality comparer

Parameters
needle
haystack
equalityComparer
Template Parameters
T
Returns

◆ IsIn< T >() [3/3]

bool PeanutButter.Utils.ExtensionsForIEnumerables.IsIn< T > ( this T needle,
T haystack,
params T[] moreHaystack )
static

tests if the needle is one of the provided items (convenience params variant)

Parameters
needle
haystack
moreHaystack
Template Parameters
T
Returns

◆ IsSameAs< T >()

bool PeanutButter.Utils.ExtensionsForIEnumerables.IsSameAs< T > ( this IEnumerable< T > collection,
IEnumerable< T > otherCollection )
static

Calculates if two collections hold the same items, irrespective of order.

Parameters
collectionSource collection
otherCollectionCollection to compare with
Template Parameters
TItem type of the collections
Returns
True if all values in the source collection are found in the target collection

◆ JoinAll()

void PeanutButter.Utils.ExtensionsForIEnumerables.JoinAll ( this IEnumerable< Thread > threads)
static

call Thread.Join for each thread in the collection

Parameters
threads

◆ JoinPath() [1/2]

string PeanutButter.Utils.ExtensionsForIEnumerables.JoinPath ( this IEnumerable< string > parts)
static

Join the parts into a path for the current platform.

Parameters
parts
Returns

◆ JoinPath() [2/2]

string PeanutButter.Utils.ExtensionsForIEnumerables.JoinPath ( this IEnumerable< string > parts,
PathType pathType )
static

Join the parts into a path for the specified platform.

Parameters
parts
pathType
Returns

◆ JoinWith< T >() [1/2]

string PeanutButter.Utils.ExtensionsForIEnumerables.JoinWith< T > ( this IEnumerable< T > collection,
char joinWith )
static

Fluent alternative to string.Join()

Parameters
collectionSource collection to operate on
joinWithString to join items with
Template Parameters
TUnderlying type of the collection
Returns
string representing items of the collection joined with the joinWith parameter. Where a collection of non-strings is provided, the objects' ToString() methods are used to get a string representation.

◆ JoinWith< T >() [2/2]

string PeanutButter.Utils.ExtensionsForIEnumerables.JoinWith< T > ( this IEnumerable< T > collection,
string joinWith )
static

Fluent alternative to string.Join()

Parameters
collectionSource collection to operate on
joinWithString to join items with
Template Parameters
TUnderlying type of the collection
Returns
string representing items of the collection joined with the joinWith parameter. Where a collection of non-strings is provided, the objects' ToString() methods are used to get a string representation.

◆ Map< TResult, TSource >()

TResult[] PeanutButter.Utils.ExtensionsForIEnumerables.Map< TResult, TSource > ( this IEnumerable< TSource > collection,
Func< TSource, TResult > transform )
static

null-safe shorthand for .Select(...).ToArray()

  • will return an empty array for a null input
Parameters
collection
transform
Template Parameters
TResult
TSource
Returns

◆ MapList< TResult, TSource >()

IList< TResult > PeanutButter.Utils.ExtensionsForIEnumerables.MapList< TResult, TSource > ( this IEnumerable< TSource > collection,
Func< TSource, TResult > transform )
static

null-safe shorthand for .Select(...).ToList()

  • will return an empty list for a null input
Parameters
collection
transform
Template Parameters
TResult
TSource
Returns

◆ Matches< T >() [1/2]

bool PeanutButter.Utils.ExtensionsForIEnumerables.Matches< T > ( this IEnumerable< T > left,
IEnumerable< T > right )
static

Performs full-collection matching on two collections of the same type, assuming that .Equals() is a valid comparator between two objects of type T.

Parameters
leftleft collection
rightright collection
Template Parameters
T
Returns
true if collections are of the same size and each item, in order, from the left item, matches the right one

◆ Matches< T >() [2/2]

bool PeanutButter.Utils.ExtensionsForIEnumerables.Matches< T > ( this IEnumerable< T > left,
IEnumerable< T > right,
Func< T, T, bool > comparer )
static

Performs matching on collections of the same type.

Parameters
leftleft collection
rightright collection
comparerfunction used to compare two values
Template Parameters
T
Returns
true if collections are of the same size and each item, in order, from the left item, matches the right one

◆ None< T >() [1/2]

bool PeanutButter.Utils.ExtensionsForIEnumerables.None< T > ( this IEnumerable< T > collection)
static

Inverse of All() LINQ method: test should return false for all elements.

Parameters
collection
Template Parameters
T
Returns

◆ None< T >() [2/2]

bool PeanutButter.Utils.ExtensionsForIEnumerables.None< T > ( this IEnumerable< T > collection,
Func< T, bool > test )
static

Inverse of All() LINQ method: test should return false for all elements.

Parameters
collection
test
Template Parameters
T
Returns

◆ Nth< T >()

T PeanutButter.Utils.ExtensionsForIEnumerables.Nth< T > ( this IEnumerable< T > src,
int n )
static

Convenience method to get the Nth item from a collection.

Parameters
srcSource collection
nZero-based index into collection
Template Parameters
T
Returns

◆ PadLeft< T >() [1/4]

IEnumerable< string > PeanutButter.Utils.ExtensionsForIEnumerables.PadLeft< T > ( this IEnumerable< T > source)
static

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.

Parameters
source
Returns

◆ PadLeft< T >() [2/4]

IEnumerable< string > PeanutButter.Utils.ExtensionsForIEnumerables.PadLeft< T > ( this IEnumerable< T > source,
char padWith )
static

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.

Parameters
source
padWith
Returns

◆ PadLeft< T >() [3/4]

IEnumerable< string > PeanutButter.Utils.ExtensionsForIEnumerables.PadLeft< T > ( this IEnumerable< T > source,
int requiredLength )
static

Returns a copy of the input strings where all are padded to the left to the provided required length with spaces.

Parameters
source
requiredLength
Returns

◆ PadLeft< T >() [4/4]

IEnumerable< string > PeanutButter.Utils.ExtensionsForIEnumerables.PadLeft< T > ( this IEnumerable< T > source,
int requiredLength,
char padWith )
static

Returns a copy of the input strings where all are padded to the left to the provided required length with the provided padWith character.

Parameters
source
requiredLength
padWith
Returns

◆ PadRight< T >() [1/4]

IEnumerable< string > PeanutButter.Utils.ExtensionsForIEnumerables.PadRight< T > ( this IEnumerable< T > source)
static

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.

Parameters
source
Returns

◆ PadRight< T >() [2/4]

IEnumerable< string > PeanutButter.Utils.ExtensionsForIEnumerables.PadRight< T > ( this IEnumerable< T > source,
char padWith )
static

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.

Parameters
source
padWith
Returns

◆ PadRight< T >() [3/4]

IEnumerable< string > PeanutButter.Utils.ExtensionsForIEnumerables.PadRight< T > ( this IEnumerable< T > source,
int requiredLength )
static

Returns a copy of the input strings where all are padded to the right with spaces char to fit to the requiredLength.

Parameters
source
requiredLength
Returns

◆ PadRight< T >() [4/4]

IEnumerable< string > PeanutButter.Utils.ExtensionsForIEnumerables.PadRight< T > ( this IEnumerable< T > source,
int requiredLength,
char padWith )
static

Returns a copy of the input strings where all are padded to the right with the padWith char to fit to the requiredLength.

Parameters
source
requiredLength
padWith
Returns

◆ Second< T >()

T PeanutButter.Utils.ExtensionsForIEnumerables.Second< T > ( this IEnumerable< T > src)
static

Convenience method to get the second item from a collection.

Parameters
srcSource collection
Template Parameters
TItem type of the collection
Returns
The second item, when available. Will throw if there is no item available.

◆ Seek< T >() [1/4]

T PeanutButter.Utils.ExtensionsForIEnumerables.Seek< T > ( this IEnumerable data)
static

Find the first item of the specified type in the collection.

Parameters
data
Template Parameters
T
Returns

◆ Seek< T >() [2/4]

T PeanutButter.Utils.ExtensionsForIEnumerables.Seek< T > ( this IEnumerable data,
Func< T, bool > predicate )
static

Finds the first element of the specified type, matching the provided predicate, or throws an exception.

Parameters
data
predicate
Template Parameters
T
Returns

◆ Seek< T >() [3/4]

T PeanutButter.Utils.ExtensionsForIEnumerables.Seek< T > ( this IEnumerable data,
int skip )
static

Find the first item of the specified type in the collection, skipping the first N elements of that type.

Parameters
data
skip
Template Parameters
T
Returns

◆ Seek< T >() [4/4]

T PeanutButter.Utils.ExtensionsForIEnumerables.Seek< T > ( this IEnumerable data,
int skip,
Func< T, bool > predicate )
static

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.

Parameters
data
skip
predicate
Template Parameters
T
Returns
Exceptions
ElementNotFoundException

◆ SeekOrDefault< T >() [1/4]

T PeanutButter.Utils.ExtensionsForIEnumerables.SeekOrDefault< T > ( this IEnumerable data)
static

Finds the first item of the specified type or returns the default value for T.

Parameters
data
Template Parameters
T
Returns

◆ SeekOrDefault< T >() [2/4]

T PeanutButter.Utils.ExtensionsForIEnumerables.SeekOrDefault< T > ( this IEnumerable data,
Func< T, bool > predicate )
static

Finds the first matching item of the specified type or returns the default value for T, after skipping N matches.

Parameters
data
predicate
Template Parameters
T
Returns

◆ SeekOrDefault< T >() [3/4]

T PeanutButter.Utils.ExtensionsForIEnumerables.SeekOrDefault< T > ( this IEnumerable data,
int skip )
static

Finds the first item of the specified type or returns the default value for T, after skipping N matches.

Parameters
data
skip
Template Parameters
T
Returns

◆ SeekOrDefault< T >() [4/4]

T PeanutButter.Utils.ExtensionsForIEnumerables.SeekOrDefault< T > ( this IEnumerable data,
int skip,
Func< T, bool > predicate )
static

Finds the first match of the specified type or returns the default value for T, after skipping N matches.

Parameters
data
skip
predicate
Template Parameters
T
Returns

◆ SelectNonNull< TCollection, TResult >() [1/2]

IEnumerable< TResult > PeanutButter.Utils.ExtensionsForIEnumerables.SelectNonNull< TCollection, TResult > ( this IEnumerable< TCollection > collection,
Func< TCollection, TResult > grabber )
static

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.

Parameters
collectionSource collection to operate over
grabberFunction to grab the data you're interested in off of each source item
Template Parameters
TCollectionItem type of the source collection
TResultItem type of the result collection
Returns
A new collection which is the result of a Select with the provided grabber where the Select results are non-null
Type Constraints
TResult :class 

◆ SelectNonNull< TCollection, TResult >() [2/2]

IEnumerable< TResult > PeanutButter.Utils.ExtensionsForIEnumerables.SelectNonNull< TCollection, TResult > ( this IEnumerable< TCollection > collection,
Func< TCollection, TResult?> grabber )
static

Convenience method to get the results of a selection where the results are non-null -> this variant works on Nullable types.

Parameters
collectionSource collection to operate over
grabberFunction to grab the data you're interested in off of each source item
Template Parameters
TCollectionItem type of the source collection
TResultItem type of the result collection
Returns
A new collection which is the result of a Select with the provided grabber where the Select results are non-null
Type Constraints
TResult :struct 

◆ StrictZip< TLeft, TRight >()

IEnumerable< Tuple< TLeft, TRight > > PeanutButter.Utils.ExtensionsForIEnumerables.StrictZip< TLeft, TRight > ( this IEnumerable< TLeft > left,
IEnumerable< TRight > right )
static

Similar to LINQ's Zip extension method, this will zip two enumerables together using yield.

  • however it will throw an exception if one enumerable runs out before the other
Parameters
leftleft collection
rightright collection
Template Parameters
TLeft
TRight
Returns
A new collection of Tuple<TLeft, TRight>

◆ StrictZip< TLeft, TRight, TResult >()

IEnumerable< TResult > PeanutButter.Utils.ExtensionsForIEnumerables.StrictZip< TLeft, TRight, TResult > ( this IEnumerable< TLeft > left,
IEnumerable< TRight > right,
Func< TLeft, TRight, TResult > generator )
static

Similar to LINQ's Zip extension method, this will zip two enumerables together using yield.

  • however it will throw an exception if one enumerable runs out before the other
Parameters
leftleft collection
rightright collection
generatorgenerator function to produce each item of TResult
Template Parameters
TLeft
TRight
TResult
Returns
A new collection of TResult, as determined by your generator function

◆ Third< T >()

T PeanutButter.Utils.ExtensionsForIEnumerables.Third< T > ( this IEnumerable< T > src)
static

Convenience method to get the third item from a collection.

Parameters
srcSource collection
Template Parameters
TItem type of the collection
Returns
The third item, when available. Will throw if there is no item available.

◆ TimesDo() [1/2]

void PeanutButter.Utils.ExtensionsForIEnumerables.TimesDo ( this int howMany,
Action toRun )
static

Fluency method to run an action a certain number of times, eg: 10.TimesDo(() => Console.WriteLine("Hello World"));.

Parameters
howManyNumber of times to run the provided action
toRunAction to run

◆ TimesDo() [2/2]

void PeanutButter.Utils.ExtensionsForIEnumerables.TimesDo ( this int howMany,
Action< int > toRun )
static

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"));.

Parameters
howManyNumber of times to run the provided action
toRunAction to run

◆ ToHashSet< T >()

HashSet< T > PeanutButter.Utils.ExtensionsForIEnumerables.ToHashSet< T > ( this IEnumerable< T > collection)
static

OBSOLETE - please use AsHashSet as ToHashSet is now implemented in the latest System.Linq.

Parameters
collection
Template Parameters
T
Returns

◆ Trim()

IEnumerable< string > PeanutButter.Utils.ExtensionsForIEnumerables.Trim ( this IEnumerable< string > source)
static

Returns the original collection of strings trimmed.

  • will handle null input as if it were an empty collection
Parameters
source
Returns

◆ TrimEnd()

IEnumerable< string > PeanutButter.Utils.ExtensionsForIEnumerables.TrimEnd ( this IEnumerable< string > source)
static

Returns the original collection of strings trimmed at the start.

  • will handle null input as if it were an empty collection
Parameters
source
Returns

◆ TrimStart()

IEnumerable< string > PeanutButter.Utils.ExtensionsForIEnumerables.TrimStart ( this IEnumerable< string > source)
static

Returns the original collection of strings trimmed at the start.

  • will handle null input as if it were an empty collection
Parameters
source
Returns

The documentation for this class was generated from the following file:
  • source/Utils/PeanutButter.Utils/ExtensionsForIEnumerables.cs