Masterly.NonEmptyList
2.0.0
dotnet add package Masterly.NonEmptyList --version 2.0.0
NuGet\Install-Package Masterly.NonEmptyList -Version 2.0.0
<PackageReference Include="Masterly.NonEmptyList" Version="2.0.0" />
<PackageVersion Include="Masterly.NonEmptyList" Version="2.0.0" />
<PackageReference Include="Masterly.NonEmptyList" />
paket add Masterly.NonEmptyList --version 2.0.0
#r "nuget: Masterly.NonEmptyList, 2.0.0"
#:package Masterly.NonEmptyList@2.0.0
#addin nuget:?package=Masterly.NonEmptyList&version=2.0.0
#tool nuget:?package=Masterly.NonEmptyList&version=2.0.0
Masterly.NonEmptyList
A simple and lightweight implementation of a non-empty list in C#, inspired by Scala's List, that ensures a collection always has at least one item. This helps in reducing null-related bugs and ensures safe operations on collections with at least one element.
Give a Star on Github! ⭐
If you like or are using this project please give it a star. Thanks!
Features
- Always contains at least one element.
- Provides
HeadandTailaccess for list traversal. - Supports indexing for element access.
- Basic list operations like
Add,Contains,Count, and more.
Installation
Install the Masterly.NonEmptyList NuGet Package.
Package Manager Console
Install-Package Masterly.NonEmptyList
.NET Core CLI
dotnet add package Masterly.NonEmptyList
Usage
// Create a NonEmptyList with a single element
var nonEmptyList = new NonEmptyList<int>(1);
Console.WriteLine(nonEmptyList.Head); // Output: 1
// Create a NonEmptyList with multiple elements
var nonEmptyListMultiple = new NonEmptyList<int>(1, 2, 3);
Console.WriteLine(nonEmptyListMultiple.Head); // Output: 1
Console.WriteLine(nonEmptyListMultiple.Tail); // Output: NonEmptyList: [2, 3]
// Add an element to the list
nonEmptyListMultiple.Add(4);
Console.WriteLine(nonEmptyListMultiple); // Output: NonEmptyList: [1, 2, 3, 4]
// Access elements by index
Console.WriteLine(nonEmptyListMultiple[1]); // Output: 2
// Check if the list contains a specific element
Console.WriteLine(nonEmptyListMultiple.Contains(3)); // Output: True
License
MIT
Free Software, Hell Yeah!
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net6.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Masterly.NonEmptyList:
| Package | Downloads |
|---|---|
|
Masterly.NonEmptyList.EntityFrameworkCore
Entity Framework Core integration for Masterly.NonEmptyList. Provides value converters, comparers, relationship configuration, and query extensions to seamlessly store and retrieve NonEmptyList and ImmutableNonEmptyList collections in your database. |
GitHub repositories
This package is not used by any popular GitHub repositories.
v2.0.0:
- Added ImmutableNonEmptyList<T> for immutable scenarios
- Added functional programming operations: Map, MapWithIndex, FlatMap, Reduce, ReduceRight, Fold, FoldRight
- Added Zip, ZipWith, ZipWithIndex operations
- Added Partition and GroupByNonEmpty methods
- Added pattern matching with Match method
- Added collection operations: Concat, Prepend, ReverseList, DistinctList, DistinctBy
- Added TakeNonEmpty, SkipNonEmpty, TakeAtLeastOne, Sliding, ChunkNonEmpty
- Added Intersperse, RotateLeft, RotateRight operations
- Added validation: RemoveAll override, SetRange, Validate, TryValidate
- Added conversion methods: ToHashSet, ToDictionary, ToQueue, ToStack, ToLinkedList, AsSpan, AsMemory
- Added utility methods: Random, MinBy, MaxBy, ForEachWithIndex
- Added async extensions: MapAsync, MapParallelAsync, ForEachAsync, FilterAsync, FoldAsync
- Added JSON serialization support with System.Text.Json
- Added TryFrom factory method for safe creation
- Added Singleton and Repeat factory methods
- Added Init property (opposite of Tail)
- Added indexer null validation
- Implemented IEquatable<T> with proper equality operators
- Multi-targeting: .NET 6.0 and .NET 8.0