Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jeevanjames/collections
Collection extensions and custom collections for .NET.
https://github.com/jeevanjames/collections
collection collections collections-framework extension-methods extensions
Last synced: about 1 month ago
JSON representation
Collection extensions and custom collections for .NET.
- Host: GitHub
- URL: https://github.com/jeevanjames/collections
- Owner: JeevanJames
- License: apache-2.0
- Created: 2018-12-15T20:22:53.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-12-30T06:52:27.000Z (11 months ago)
- Last Synced: 2024-04-26T17:22:49.328Z (7 months ago)
- Topics: collection, collections, collections-framework, extension-methods, extensions
- Language: C#
- Size: 337 KB
- Stars: 9
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Collections.NET [![Build status](https://img.shields.io/appveyor/ci/JeevanJames/collections.svg)](https://ci.appveyor.com/project/JeevanJames/collections/branch/master) [![Test status](https://img.shields.io/appveyor/tests/JeevanJames/collections.svg)](https://ci.appveyor.com/project/JeevanJames/collections/branch/master) [![codecov](https://codecov.io/gh/JeevanJames/Collections/branch/master/graph/badge.svg)](https://codecov.io/gh/JeevanJames/Collections) [![NuGet Version](http://img.shields.io/nuget/v/Collections.NET.svg?style=flat)](https://www.nuget.org/packages/Collections.NET/) [![NuGet Downloads](https://img.shields.io/nuget/dt/Collections.NET.svg)](https://www.nuget.org/packages/Collections.NET/)
Collections.NET is a set of collection extensions and custom collections.
All code in this package is under the `System.Collections.Generic` namespace, so you automatically have access to the extension methods simply by using the namespace.
## Nuget installation
Install using package manager:
```ps
PM> Install-Package Collections.NET
```Install using `dotnet` CLI:
```sh
> dotnet add package Collections.NET
```## Collection extensions
Extension methods for common collection interfaces like `IEnumerable`, `ICollection` and `IList`.|Method name|Interface|Description|
|-----------|---------|-----------|
|`AddRange`|`ICollection`|Adds one or more items to a collection in a single operation. Inspired by the `List.AddRange` method.|
|`AllOrNone`|`IEnumerable`|Determines whether all or none of the elements in a sequence match a predicate.|
|`Chunk`|`IEnumerable`|Splits a collection into chunks of a specified size.|
|`Fill`|`IList`|Sets all elements in a collection to a specific value.|
|`ForEach`|`IEnumerable`|Iterates over each element in a collection and calls the specified delegate for each item. Inspired by the `List.ForEach` method.|
|`IndexOf`|`IList`|Finds the index of the first matching element in a collection based on the specified predicate.|
|`IndexOfAll`|`IList`|Finds all indices of the matching elements in a collection based on the specified predicate.|
|`InsertRange`|`IList`|Inserts one or more items into a collection at the given location in a single operation.|
|`IsEmpty`|`IEnumerable`|Indicates whether a collection is empty. A better way of doing `if !collection.Any()`|
|`IsNotNullOrEmpty`|`IEnumerable`|Determines whether a sequence is not `null` and has at least one element.|
|`IsNullOrEmpty`|`IEnumerable`|Indicates whether a collection is `null` or empty.|
|`LastIndexOf`|`IList`|Finds the index of the last matching element in a collection based on the specified predicate.|
|`None`|`IEnumerable`|Determines whether none of the elements in a collection satisfies the specified predicate. Opposite of the LINQ `All` extension method.|
|`Partition`|`IEnumerable`|Checks each element in a collection against a predicate and returns the elements that match and the elements that do not.|
|`Random`|`IList`|Creates a collection of the specified size with random values picked from a specified collection.|
|`Range`|`ICollection`|Returns an iterator for the elements in the collection from the specified start index to the end index.|
|`RemoveAll`|`IList`|Removes all elements from a collection that satisfies the specified predicate.|
|`RemoveFirst`|`IList`|Removes the first element from a collection that satisfies the specified predicate.|
|`RemoveLast`|`IList`|Removes the last elements from a collection that satisfies the specified predicate.|
|`Repeat`|`IEnumerable`|Creates a collection that contains the specified collection repeated a specified number of times.|
|`Shuffle`|`IEnumerable`|Returns a shuffled collection from a given collection.|
|`ShuffleInplace`|`IList`|Shuffles the elements of a collection.|
|`SlidingChunk`|`IList`|Returns overlapping chunks of elements of the specified size from a collection.|
|`ToArray`|`IEnumerable`|Creates an array from a collection. Overloads available to select the elements from the collection to be included in the array based on a predicate, and to convert the elements to a different type.|
|`ToList`|`IEnumerable`|Creates a `List` from a collection. Overloads available to select the elements from the collection to be included in the array based on a predicate, and to convert the elements to a different type.|
|`Union`|`IEnumerable`|Produces a set union of two sequences.|
|`WhereNot`|`IEnumerable`|Filters a collection on the values that do not match the specified predicate. Inverse of the LINQ `Where` method.|## Dictionary extensions
Extension methods on the `IDictionary` interface.|Method name|Description|
|-----------|-----------|
|`AddOrUpdate`|Adds a new entry for a specified key if it doesn't already exist, otherwise updates the existing entry.|
|`GetValueOrDefault`|Gets a value for a specified key or a default value if the key does not exist.|
|`GetValueOrAdd`|Gets a value for a specified key or adds an entry if the key does not exist.|## Byte array extensions
Extension methods that provide commonly-used operations on `byte` arrays.> Since .NET arrays implement `IList`, most of the extension methods operate on `IList` rather than just `byte[]`. The documentation will continue to refer to them as byte arrays.
|Method name|Description|
|-----------|-----------|
|`IsEqualTo`|Checks whether two byte collections contain the same data.|
|`IsNullOrZeroed`|Indicates whether a byte collection is `null`, empty or contains only zeroes.|
|`IsZeroed`|Indicates whether a byte collection is empty or contains only zeroes.|
|`ToString`|Joins all values in a byte collection using a specified delimiter.|### Byte sequence operations
The byte array extensions also provide a number of methods to deal with sequences of bytes:|Method name|Description|
|-----------|-----------|
|`GetBytesUptoSequence`|Gets all the bytes in a byte array up to the specified byte sequence.|
|`IndexOfSequence`|Gets the index of the first occurence of the specified byte sequence in a byte array.|
|`IndexOfSequences`|Gets all indices of the occurences of the specified byte sequence in a byte array.|
|`SplitBySequence`|Splits a byte array by the specified byte sequence.|## `EnumIterator` class
The `EnumIterator` class provides two static methods to create an iterator for the values of an `enum`.```cs
// First overload - takes a generic type parameter for the enum type
foreach (DayOfWeek day in EnumIterator.For())
{
Console.WriteLine(day);
}// Second overload - non-generic method that accepts Type parameter.
List days = EnumIterator.For(typeof(DayOfWeek)).ToList();
days.ForEach(Console.WriteLine);
```