An open API service indexing awesome lists of open source software.

https://github.com/soenneker/soenneker.extensions.enumerable

A collection of helpful enumerable extension methods
https://github.com/soenneker/soenneker.extensions.enumerable

csharp dotnet extension ienumerable

Last synced: 5 months ago
JSON representation

A collection of helpful enumerable extension methods

Awesome Lists containing this project

README

        

[![](https://img.shields.io/nuget/v/Soenneker.Extensions.Enumerable.svg?style=for-the-badge)](https://www.nuget.org/packages/Soenneker.Extensions.Enumerable/)
[![](https://img.shields.io/github/actions/workflow/status/soenneker/soenneker.extensions.enumerable/publish-package.yml?style=for-the-badge)](https://github.com/soenneker/soenneker.extensions.enumerable/actions/workflows/publish-package.yml)
[![](https://img.shields.io/nuget/dt/Soenneker.Extensions.Enumerable.svg?style=for-the-badge)](https://www.nuget.org/packages/Soenneker.Extensions.Enumerable/)

# ![](https://user-images.githubusercontent.com/4441470/224455560-91ed3ee7-f510-4041-a8d2-3fc093025112.png) Soenneker.Extensions.Enumerable
### A collection of helpful enumerable extension methods

## Installation

```
dotnet add package Soenneker.Extensions.Enumerable
```

## Usage

### `IEnumerable` should have `IsNullOrEmpty()` too

```csharp
var populatedList = new List{"foo", "bar", "foo"};

populatedList.IsNullOrEmpty() // false

populatedList.Populated() // true
populatedList.None() // false
```

## One call checking for null and contains any elements

```csharp
List? nullList = null;

nullList.IsNullOrEmpty() // true
nullList.Populated() // false
```

### Duplicate handling

```csharp
var containsDuplicates = populatedList.ContainsDuplicates(); // true

var deduped = populatedList.RemoveDuplicates(); // {"foo", "bar"}
```

### Recursive flattening

```csharp
public class Node
{
public string Name {get; set;}
public List Children {get; set;}
}

void Example()
{
var node = new Node(){ Name = "Node1" };
node.Children = new List()
{
new Node()
{
Name = "Node2"
}
}

List? children = node.Children.ToFlattenedFromRecursive(c => c.Children);

// Results in flattened List:
// { Node1, Node2 }
}
```