Masterly.NonEmptyList
1.2.1
dotnet add package Masterly.NonEmptyList --version 1.2.1
NuGet\Install-Package Masterly.NonEmptyList -Version 1.2.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Masterly.NonEmptyList" Version="1.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Masterly.NonEmptyList --version 1.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Masterly.NonEmptyList, 1.2.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Masterly.NonEmptyList as a Cake Addin #addin nuget:?package=Masterly.NonEmptyList&version=1.2.1 // Install Masterly.NonEmptyList as a Cake Tool #tool nuget:?package=Masterly.NonEmptyList&version=1.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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
Head
andTail
access 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 was computed. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.