public static partial class Enumerable
{
public static IEnumerable<TResult> Empty<TResult>() => Array.Empty<TResult>();
+
+ private static IEnumerable<TResult>? GetEmptyIfEmpty<TSource, TResult>(IEnumerable<TSource> source) =>
+ source is TSource[] { Length: 0 } ?
+ Array.Empty<TResult>() :
+ null;
}
}
public static partial class Enumerable
{
public static IEnumerable<TResult> Empty<TResult>() => EmptyPartition<TResult>.Instance;
+
+ private static IEnumerable<TResult>? GetEmptyIfEmpty<TSource, TResult>(IEnumerable<TSource> source) =>
+ source is EmptyPartition<TSource> ?
+ EmptyPartition<TResult>.Instance :
+ null;
}
}
static partial void CreateSelectIPartitionIterator<TResult, TSource>(
Func<TSource, TResult> selector, IPartition<TSource> partition, ref IEnumerable<TResult>? result)
{
- result = partition is EmptyPartition<TSource> ?
- EmptyPartition<TResult>.Instance :
- new SelectIPartitionIterator<TSource, TResult>(partition, selector);
+ result = new SelectIPartitionIterator<TSource, TResult>(partition, selector);
}
private sealed partial class SelectEnumerableIterator<TSource, TResult> : IIListProvider<TResult>
return iterator.Select(selector);
}
+ if (GetEmptyIfEmpty<TSource, TResult>(source) is IEnumerable<TResult> empty)
+ {
+ return empty;
+ }
+
if (source is IList<TSource> ilist)
{
if (source is TSource[] array)