With extension methods, we can write handy LINQ operators which solve generic problems.
I want to hear which methods or overloads you are missing in the System.Linq
namespace and how you implemented them.
Clean and elegant implementations, maybe using existing methods, are preferred.
InsertBetween
Inserts an element in between every pair of consecutive elements.
SkipLast & TakeLast
Parse
This one involves a custom delegate (could've used an
IParser<T>
interface instead, but I went with a delegate as it was simpler), which is used to parse a sequence of strings to a sequence of values, skipping the elements where parsing fails.Usage:
Output:
Naming's tricky for this one. I'm not sure whether
Parse
is the best option (it is simple, at least), or if something likeParseWhereValid
would be better.ZipMerge
This is my version of
Zip
which works like a real zipper. It does not project two values into one but returns a combined IEnumerable. Overloads, skipping the right and/or left tail are possible.One, Two, MoreThanOne, AtLeast, AnyAtAll
ToList and ToDictionary with Initial Capacity
ToList and ToDictionary overloads that expose the underlying collection classes' initial capacity. Occasionally useful when source length is known or bounded.