Class IEnumerableOfTExtensions
- Namespace
- Songhay.Extensions
- Assembly
- SonghayCore.dll
Extensions of IEnumerable<T>.
public static class IEnumerableOfTExtensions
- Inheritance
-
IEnumerableOfTExtensions
- Inherited Members
Remarks
When this ‘greatest hits collection’ is found to be limited, upgrade to MoreLinq [ see https://github.com/morelinq/MoreLINQ ]
Methods
Flatten<TSource>(IEnumerable<TSource>?, Func<TSource, IEnumerable<TSource>>?)
Flattens the specified source.
public static IEnumerable<TSource> Flatten<TSource>(this IEnumerable<TSource>? source, Func<TSource, IEnumerable<TSource>>? childGetter)
Parameters
source
IEnumerable<TSource>The source.
childGetter
Func<TSource, IEnumerable<TSource>>The child getter.
Returns
- IEnumerable<TSource>
Type Parameters
TSource
The type of the source.
Remarks
When source
is not already an array,
this member will mercilessly allocate a snapshot of TSource[]
.
To avoid this memory pressure, upgrade to the Flatten
method
of MoreLinq [ see https://github.com/morelinq/MoreLINQ/blob/master/MoreLinq/Flatten.cs#L91 ]
Flatten<TSource>(IEnumerable<TSource>, Func<TSource, IEnumerable<TSource>>, TSource)
Flattens the specified source.
public static IEnumerable<TSource> Flatten<TSource>(this IEnumerable<TSource> source, Func<TSource, IEnumerable<TSource>> childGetter, TSource flattenedHead)
Parameters
source
IEnumerable<TSource>The source.
childGetter
Func<TSource, IEnumerable<TSource>>The child getter.
flattenedHead
TSourceThe flattened head.
Returns
- IEnumerable<TSource>
Type Parameters
TSource
The type of the source.
ForEachInEnumerable<TEnumerable>(IEnumerable<TEnumerable>?, Action<TEnumerable, int>?)
Performs the Action on each item in the enumerable object.
public static void ForEachInEnumerable<TEnumerable>(this IEnumerable<TEnumerable>? enumerable, Action<TEnumerable, int>? action)
Parameters
enumerable
IEnumerable<TEnumerable>The enumerable.
action
Action<TEnumerable, int>The action.
Type Parameters
TEnumerable
The type of the enumerable.
Remarks
This member is ruthlessly derived from MoreLinq.ForEach{T}
[ see https://github.com/morelinq/MoreLINQ/blob/master/MoreLinq/ForEach.cs#L50 ].
ForEachInEnumerable<TEnumerable>(IEnumerable<TEnumerable>?, Action<TEnumerable>?)
Performs the Action on each item in the enumerable object.
public static void ForEachInEnumerable<TEnumerable>(this IEnumerable<TEnumerable>? enumerable, Action<TEnumerable>? action)
Parameters
enumerable
IEnumerable<TEnumerable>The enumerable.
action
Action<TEnumerable>The action.
Type Parameters
TEnumerable
The type of the enumerable.
Remarks
“I am philosophically opposed to providing such a method, for two reasons. …The first reason is that doing so violates the functional programming principles that all the other sequence operators are based upon. Clearly the sole purpose of a call to this method is to cause side effects.” —Eric Lippert, “foreach” vs “ForEach” [http://blogs.msdn.com/b/ericlippert/archive/2009/05/18/foreach-vs-foreach.aspx]
Partition<T>(IEnumerable<T>, int)
Partitions the specified source.
public static IEnumerable<IEnumerable<T>> Partition<T>(this IEnumerable<T> source, int size)
Parameters
source
IEnumerable<T>The source.
size
intThe size.
Returns
Type Parameters
T
Remarks
This member is by Jon Skeet. [http://stackoverflow.com/questions/438188/split-a-collection-into-n-parts-with-linq]
SelectWithPrevious<TSource, TResult>(IEnumerable<TSource>, Func<TSource, TSource, TResult>)
Projects the previous item with the current item.
public static IEnumerable<TResult> SelectWithPrevious<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TSource, TResult> projection)
Parameters
source
IEnumerable<TSource>The source.
projection
Func<TSource, TSource, TResult>The projection.
Returns
- IEnumerable<TResult>
Type Parameters
TSource
The type of the source.
TResult
The type of the result.
Remarks
“This enables you to perform your projection using only a single pass of the source sequence, which is always a bonus (imagine running it over a large log file). Note that it will project a sequence of length n into a sequence of length n-1— you may want to prepend a ‘dummy’ first element, for example. (Or change the method to include one.) Here’s an example of how you'd use it:
var query = list.SelectWithPrevious((prev, cur) => new { ID = cur.ID, Date = cur.Date, DateDiff = (cur.Date - prev.Date).Days);
Note that this will include the final result of one ID with the first result of the next ID… you may wish to group your sequence by ID first.” —Jon Skeet, “Calculate difference from previous item with LINQ” [http://stackoverflow.com/questions/3683105/calculate-difference-from-previous-item-with-linq/3683217#3683217]
ToCollection<TEnumerable>(IEnumerable<TEnumerable>?)
Converts the IEnumerable<T> into ICollection<T>.
public static ICollection<TEnumerable> ToCollection<TEnumerable>(this IEnumerable<TEnumerable>? enumerable)
Parameters
enumerable
IEnumerable<TEnumerable>
Returns
- ICollection<TEnumerable>
Type Parameters
TEnumerable
Remarks
For details, see “When To Use IEnumerable, ICollection, IList And List” [http://www.claudiobernasconi.ch/2013/07/22/when-to-use-ienumerable-icollection-ilist-and-list/]
ToDisplayString<TSource>(IEnumerable<TSource>)
Converts the IEnumerable<T> into a display string.
public static string ToDisplayString<TSource>(this IEnumerable<TSource> data) where TSource : class
Parameters
data
IEnumerable<TSource>The source.
Returns
Type Parameters
TSource
The type of the source.
ToDisplayString<TSource>(IEnumerable<TSource>, byte)
Converts the IEnumerable<T> into a display string.
public static string ToDisplayString<TSource>(this IEnumerable<TSource> source, byte indent) where TSource : class
Parameters
source
IEnumerable<TSource>The source.
indent
byteThe indent.
Returns
Type Parameters
TSource
The type of the source.