Masterly.NonEmptyList 1.2.1

There is a newer version of this package available.
See the version list below for details.
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.
<PackageVersion Include="Masterly.NonEmptyList" Version="1.2.1" />
                    
Directory.Packages.props
<PackageReference Include="Masterly.NonEmptyList" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Masterly.NonEmptyList --version 1.2.1
                    
#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.
#:package Masterly.NonEmptyList@1.2.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Masterly.NonEmptyList&version=1.2.1
                    
Install as a Cake Addin
#tool nuget:?package=Masterly.NonEmptyList&version=1.2.1
                    
Install as a Cake Tool

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 and Tail 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 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.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages (7)

Showing the top 5 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.

Masterly.NonEmptyList.AspNetCore

ASP.NET Core integration for Masterly.NonEmptyList: OpenAPI schema transformer that emits minItems/minLength/uniqueItems for every non-empty type, Validation-to-HTTP result helpers that turn accumulated errors into RFC 7807 validation problem details, and ModelState helpers for MVC.

Masterly.NonEmptyList.Configuration

Microsoft.Extensions.Configuration and Options integration for Masterly.NonEmptyList. Binds NonEmptyList, NonEmptySet, NonEmptyDictionary, ConstrainedList and NonEmptyString properties from configuration (arrays or comma-separated values) and fails at startup, naming the key, when a required collection is empty or missing.

Masterly.NonEmptyList.Dapper

Dapper type handlers for Masterly.NonEmptyList. Stores NonEmptyList, ImmutableNonEmptyList, NonEmptySet, ConstrainedList and NonEmptyDictionary columns as JSON text and NonEmptyString as text, rejecting empty values when reading.

Masterly.NonEmptyList.Testing

Test support for Masterly.NonEmptyList: CsCheck generators for every non-empty type, an AutoFixture customization, and the published law suite (functor, monad, fold and structural laws) so property-based tests can verify your own code and extensions.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.1 234 11/2/2026
3.0.0 220 11/2/2026
2.0.0 241 1/1/2026
1.2.2 157 1/1/2026
1.2.1 262 9/15/2024
1.2.0 218 9/15/2024
1.1.0 216 9/15/2024
1.0.0 220 9/13/2024