Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/a7mdfre7at/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.
https://github.com/a7mdfre7at/masterly.nonemptylist
a7mdfre7at csharp data-structures dotnet dotnet-core functional-programming list masterly non-empty non-empty-collections scala-list-like
Last synced: about 1 month ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/a7mdfre7at/masterly.nonemptylist
- Owner: a7mdfre7at
- License: mit
- Created: 2024-09-13T17:22:26.000Z (2 months ago)
- Default Branch: master
- Last Pushed: 2024-09-15T18:39:11.000Z (2 months ago)
- Last Synced: 2024-10-13T01:41:32.438Z (about 1 month ago)
- Topics: a7mdfre7at, csharp, data-structures, dotnet, dotnet-core, functional-programming, list, masterly, non-empty, non-empty-collections, scala-list-like
- Language: C#
- Homepage: https://github.com/a7mdfre7at/Masterly.NonEmptyList
- Size: 87.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# 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.[![Nuget](https://img.shields.io/nuget/v/Masterly.NonEmptyList?style=flat-square)](https://www.nuget.org/packages/Masterly.NonEmptyList) ![Nuget](https://img.shields.io/nuget/dt/Masterly.NonEmptyList?style=flat-square) ![GitHub last commit](https://img.shields.io/github/last-commit/a7mdfre7at/Masterly.NonEmptyList?style=flat-square) ![GitHub](https://img.shields.io/github/license/a7mdfre7at/Masterly.NonEmptyList?style=flat-square) [![Build](https://github.com/a7mdfre7at/Masterly.NonEmptyList/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/a7mdfre7at/Masterly.NonEmptyList/actions/workflows/build.yml) [![CodeQL Analysis](https://github.com/a7mdfre7at/Masterly.NonEmptyList/actions/workflows/codeql.yml/badge.svg?branch=master)](https://github.com/a7mdfre7at/Masterly.NonEmptyList/actions/workflows/codeql.yml) [![Publish to NuGet](https://github.com/a7mdfre7at/Masterly.NonEmptyList/actions/workflows/publish.yml/badge.svg?branch=master)](https://github.com/a7mdfre7at/Masterly.NonEmptyList/actions/workflows/publish.yml)
## Give a Star! :star:
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](https://www.nuget.org/packages/Masterly.NonEmptyList).
### Package Manager Console
```
Install-Package Masterly.NonEmptyList
```### .NET Core CLI
```
dotnet add package Masterly.NonEmptyList
```## Usage
````csharp
// Create a NonEmptyList with a single element
var nonEmptyList = new NonEmptyList(1);
Console.WriteLine(nonEmptyList.Head); // Output: 1// Create a NonEmptyList with multiple elements
var nonEmptyListMultiple = new NonEmptyList(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!**