Collection extensions and custom collections for .NET.
APACHE-2.0 License
Bot releases are hidden (Show)
Union
extension that allow single values to be added.Where earlier you would have done this:
var nums = new int[] { 1, 2, 3, 4, 5, 6 };
nums.Union(new[] { 7 });
You can now do this:
var nums = new int[] { 1, 2, 3, 4, 5, 6 };
nums.Union(7);
Another Union
overload accepts a params
parameter:
var nums = new int[] { 1, 2, 3, 4, 5, 6 };
nums.Union(7, 8, 9);
Added an AllOrNone
extension on IEnumerable<T>
that determines whether a predicate matches all or none of the elements in a sequence.
Added an IsNotNullOrEmpty
extension, which is the opposite of IsNullOrEmpty
.
Published by JeevanJames over 5 years ago
char
, int
, long
and short
.Published by JeevanJames over 5 years ago
Added SlidingChunk
extension method, which returns overlapping consecutive chunks of a specified size from a collection.
This is different from the Chunk
extension method, which returns non-overlapping chunks.
var collection = new List<int> {1, 2, 3, 4, 5, 6};
var chunks = collection.Chunk(2);
// returns { {1, 2}, {3, 4}, {5, 6} }
var slidingChunks = collection.SlidingChunk(2);
// returns { {1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6} }
Published by JeevanJames almost 6 years ago
ForEach
methods now return the original collection to allow for fluent syntax.
The AddRange
overload that accepts a predicate and a converter takes an additional parameter - a predicate that works on the converted data. The first predicate parameter works on the data before it is converted.
var list = new List<int> {1, 2, 3};
var dataToAdd = new[] {"7", "8", "9", "10", "11", "12"};
list.Add(dataToAdd,
s => s.Length == 1, // Predicate on string - only strings of length 1
s => int.Parse, // Converter - converts string to int
n => n % 2 == 0); // Predicate on int - only even numbers
InsertRange
extension methods on IList<T>
that inserts one or more items to a collection at a specific location.Moved methods from CollectionExtensions
class to other classes based on the interface they are extending. So, methods that extend IEnumerable<T>
are moved to EnumerableExtensions
and methods that extend IList<T>
are moved to ListExtensions
. Methods that extend ICollection<T>
remain in the same class.
This is only a breaking change if you call these methods as static methods instead of as extension methods.
int[] array = new int[10];
// Calling as a static method - This will break
CollectionExtensions.Fill(array, 7);
// Calling as an extension method - This will not break
array.Fill(7);
Published by JeevanJames almost 6 years ago