Masterly.NonEmptyList 2.0.0

dotnet add package Masterly.NonEmptyList --version 2.0.0
                    
NuGet\Install-Package Masterly.NonEmptyList -Version 2.0.0
                    
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="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Masterly.NonEmptyList" Version="2.0.0" />
                    
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 2.0.0
                    
#r "nuget: Masterly.NonEmptyList, 2.0.0"
                    
#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@2.0.0
                    
#: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=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Masterly.NonEmptyList&version=2.0.0
                    
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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.

Version Downloads Last Updated
2.0.0 78 1/1/2026
1.2.2 69 1/1/2026
1.2.1 204 9/15/2024
1.2.0 160 9/15/2024
1.1.0 156 9/15/2024
1.0.0 161 9/13/2024

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