mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-11-17 19:08:53 -07:00
35 lines
950 B
C#
35 lines
950 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Rssdp.Infrastructure
|
|
{
|
|
internal static class IEnumerableExtensions
|
|
{
|
|
public static IEnumerable<T> SelectManyRecursive<T>(this IEnumerable<T> source, Func<T, IEnumerable<T>> selector)
|
|
{
|
|
if (source == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(source));
|
|
}
|
|
|
|
if (selector == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(selector));
|
|
}
|
|
|
|
return !source.Any() ? source :
|
|
source.Concat(
|
|
source
|
|
.SelectMany(i => selector(i).EmptyIfNull())
|
|
.SelectManyRecursive(selector)
|
|
);
|
|
}
|
|
|
|
public static IEnumerable<T> EmptyIfNull<T>(this IEnumerable<T> source)
|
|
{
|
|
return source ?? Enumerable.Empty<T>();
|
|
}
|
|
}
|
|
}
|