Skip to content

Simplify collections, and produce less pooling work #79153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/Dependencies/Collections/Extensions/IEnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static ImmutableArray<T> ToImmutableArrayOrEmpty<T>(this IEnumerable<T>?
{
if (items == null)
{
return ImmutableArray.Create<T>();
return [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I don't normally mind the change, if this is a source package does this create a problem for any of our consumers that aren't on a new enough compiler?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Collection expressions were C# 12. we're already about to ship 14. I would expect at most we would want people on N-1. Not arbitrarily far back.

}

if (items is ImmutableArray<T> array)
Expand Down Expand Up @@ -436,7 +436,7 @@ public static ImmutableArray<TResult> SelectAsArray<TSource, TResult>(this IEnum
{
if (source == null)
{
return ImmutableArray<TResult>.Empty;
return [];
}

var builder = ArrayBuilder<TResult>.GetInstance();
Expand All @@ -448,7 +448,7 @@ public static ImmutableArray<TResult> SelectAsArray<TSource, TResult>(this IEnum
public static ImmutableArray<TResult> SelectAsArray<TSource, TResult>(this IEnumerable<TSource>? source, Func<TSource, int, TResult> selector)
{
if (source == null)
return ImmutableArray<TResult>.Empty;
return [];

var builder = ArrayBuilder<TResult>.GetInstance();

Expand All @@ -465,7 +465,7 @@ public static ImmutableArray<TResult> SelectAsArray<TSource, TResult>(this IEnum
public static ImmutableArray<TResult> SelectAsArray<TSource, TResult>(this IReadOnlyCollection<TSource>? source, Func<TSource, TResult> selector)
{
if (source == null)
return ImmutableArray<TResult>.Empty;
return [];

var builder = new TResult[source.Count];
var index = 0;
Expand All @@ -481,7 +481,7 @@ public static ImmutableArray<TResult> SelectAsArray<TSource, TResult>(this IRead
public static ImmutableArray<TResult> SelectAsArray<TSource, TResult, TArg>(this IReadOnlyCollection<TSource>? source, Func<TSource, TArg, TResult> selector, TArg arg)
{
if (source == null)
return ImmutableArray<TResult>.Empty;
return [];

var builder = new TResult[source.Count];
var index = 0;
Expand All @@ -497,7 +497,7 @@ public static ImmutableArray<TResult> SelectAsArray<TSource, TResult, TArg>(this
public static ImmutableArray<TResult> SelectManyAsArray<TSource, TResult>(this IEnumerable<TSource>? source, Func<TSource, IEnumerable<TResult>> selector)
{
if (source == null)
return ImmutableArray<TResult>.Empty;
return [];

var builder = ArrayBuilder<TResult>.GetInstance();
foreach (var item in source)
Expand All @@ -509,7 +509,7 @@ public static ImmutableArray<TResult> SelectManyAsArray<TSource, TResult>(this I
public static ImmutableArray<TResult> SelectManyAsArray<TItem, TArg, TResult>(this IEnumerable<TItem>? source, Func<TItem, TArg, IEnumerable<TResult>> selector, TArg arg)
{
if (source == null)
return ImmutableArray<TResult>.Empty;
return [];

var builder = ArrayBuilder<TResult>.GetInstance();
foreach (var item in source)
Expand All @@ -521,7 +521,7 @@ public static ImmutableArray<TResult> SelectManyAsArray<TItem, TArg, TResult>(th
public static ImmutableArray<TResult> SelectManyAsArray<TItem, TResult>(this IReadOnlyCollection<TItem>? source, Func<TItem, IEnumerable<TResult>> selector)
{
if (source == null)
return ImmutableArray<TResult>.Empty;
return [];

// Basic heuristic. Assume each element in the source adds one item to the result.
var builder = ArrayBuilder<TResult>.GetInstance(source.Count);
Expand All @@ -534,7 +534,7 @@ public static ImmutableArray<TResult> SelectManyAsArray<TItem, TResult>(this IRe
public static ImmutableArray<TResult> SelectManyAsArray<TItem, TArg, TResult>(this IReadOnlyCollection<TItem>? source, Func<TItem, TArg, IEnumerable<TResult>> selector, TArg arg)
{
if (source == null)
return ImmutableArray<TResult>.Empty;
return [];

// Basic heuristic. Assume each element in the source adds one item to the result.
var builder = ArrayBuilder<TResult>.GetInstance(source.Count);
Expand All @@ -547,7 +547,7 @@ public static ImmutableArray<TResult> SelectManyAsArray<TItem, TArg, TResult>(th
public static ImmutableArray<TResult> SelectManyAsArray<TSource, TResult>(this IEnumerable<TSource>? source, Func<TSource, OneOrMany<TResult>> selector)
{
if (source == null)
return ImmutableArray<TResult>.Empty;
return [];

var builder = ArrayBuilder<TResult>.GetInstance();
foreach (var item in source)
Expand Down
70 changes: 35 additions & 35 deletions src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
{
if (items == null)
{
return ImmutableArray<T>.Empty;
return [];
}

return ImmutableArray.CreateRange<T>(items);
Expand Down Expand Up @@ -115,7 +115,7 @@
{
if (items == null)
{
return ImmutableArray<T>.Empty;
return [];
}

return ImmutableArray.Create<T>(items);
Expand Down Expand Up @@ -174,28 +174,28 @@
switch (items.Length)
{
case 0:
return ImmutableArray<TResult>.Empty;
return [];

case 1:
return ImmutableArray.Create(map(items[0], 0, arg));
return [map(items[0], 0, arg)];

case 2:
return ImmutableArray.Create(map(items[0], 0, arg), map(items[1], 1, arg));
return [map(items[0], 0, arg), map(items[1], 1, arg)];

case 3:
return ImmutableArray.Create(map(items[0], 0, arg), map(items[1], 1, arg), map(items[2], 2, arg));
return [map(items[0], 0, arg), map(items[1], 1, arg), map(items[2], 2, arg)];

case 4:
return ImmutableArray.Create(map(items[0], 0, arg), map(items[1], 1, arg), map(items[2], 2, arg), map(items[3], 3, arg));
return [map(items[0], 0, arg), map(items[1], 1, arg), map(items[2], 2, arg), map(items[3], 3, arg)];

default:
var builder = ArrayBuilder<TResult>.GetInstance(items.Length);
var builder = new FixedSizeArrayBuilder<TResult>(items.Length);
for (int i = 0; i < items.Length; i++)
{
builder.Add(map(items[i], i, arg));
}

return builder.ToImmutableAndFree();
return builder.MoveToImmutable();
}
}

Expand All @@ -212,7 +212,7 @@
{
if (array.Length == 0)
{
return ImmutableArray<TResult>.Empty;
return [];
}

var builder = ArrayBuilder<TResult>.GetInstance();
Expand Down Expand Up @@ -242,7 +242,7 @@
{
if (array.Length == 0)
{
return ImmutableArray<TResult>.Empty;
return [];
}

var builder = ArrayBuilder<TResult>.GetInstance();
Expand All @@ -268,7 +268,7 @@
public static ImmutableArray<TResult> SelectManyAsArray<TItem, TResult>(this ImmutableArray<TItem> array, Func<TItem, IEnumerable<TResult>> selector)
{
if (array.Length == 0)
return ImmutableArray<TResult>.Empty;
return [];

var builder = ArrayBuilder<TResult>.GetInstance();
foreach (var item in array)
Expand All @@ -288,7 +288,7 @@
public static ImmutableArray<TResult> SelectManyAsArray<TItem, TResult>(this ImmutableArray<TItem> array, Func<TItem, ImmutableArray<TResult>> selector)
{
if (array.Length == 0)
return ImmutableArray<TResult>.Empty;
return [];

var builder = ArrayBuilder<TResult>.GetInstance();
foreach (var item in array)
Expand All @@ -308,7 +308,7 @@
public static ImmutableArray<TResult> SelectManyAsArray<TItem, TResult>(this ImmutableArray<TItem> array, Func<TItem, OneOrMany<TResult>> selector)
{
if (array.Length == 0)
return ImmutableArray<TResult>.Empty;
return [];

var builder = ArrayBuilder<TResult>.GetInstance();
foreach (var item in array)
Expand All @@ -331,7 +331,7 @@
public static ImmutableArray<TResult> SelectManyAsArray<TItem, TResult>(this ImmutableArray<TItem> array, Func<TItem, bool> predicate, Func<TItem, IEnumerable<TResult>> selector)
{
if (array.Length == 0)
return ImmutableArray<TResult>.Empty;
return [];

var builder = ArrayBuilder<TResult>.GetInstance();
foreach (var item in array)
Expand All @@ -355,7 +355,7 @@
public static ImmutableArray<TResult> SelectManyAsArray<TItem, TResult>(this ImmutableArray<TItem> array, Func<TItem, bool> predicate, Func<TItem, ImmutableArray<TResult>> selector)
{
if (array.Length == 0)
return ImmutableArray<TResult>.Empty;
return [];

var builder = ArrayBuilder<TResult>.GetInstance();
foreach (var item in array)
Expand All @@ -379,7 +379,7 @@
public static ImmutableArray<TResult> SelectManyAsArray<TItem, TResult>(this ImmutableArray<TItem> array, Func<TItem, bool> predicate, Func<TItem, OneOrMany<TResult>> selector)
{
if (array.Length == 0)
return ImmutableArray<TResult>.Empty;
return [];

var builder = ArrayBuilder<TResult>.GetInstance();
foreach (var item in array)
Expand All @@ -404,7 +404,7 @@
public static ImmutableArray<TResult> SelectManyAsArray<TItem, TArg, TResult>(this ImmutableArray<TItem> array, Func<TItem, TArg, bool> predicate, Func<TItem, TArg, OneOrMany<TResult>> selector, TArg arg)
{
if (array.Length == 0)
return ImmutableArray<TResult>.Empty;
return [];

var builder = ArrayBuilder<TResult>.GetInstance();
foreach (var item in array)
Expand All @@ -422,7 +422,7 @@
public static async ValueTask<ImmutableArray<TResult>> SelectAsArrayAsync<TItem, TResult>(this ImmutableArray<TItem> array, Func<TItem, CancellationToken, ValueTask<TResult>> selector, CancellationToken cancellationToken)
{
if (array.IsEmpty)
return ImmutableArray<TResult>.Empty;
return [];

var builder = new TResult[array.Length];

Expand All @@ -440,7 +440,7 @@
public static async ValueTask<ImmutableArray<TResult>> SelectAsArrayAsync<TItem, TArg, TResult>(this ImmutableArray<TItem> array, Func<TItem, TArg, CancellationToken, ValueTask<TResult>> selector, TArg arg, CancellationToken cancellationToken)
{
if (array.IsEmpty)
return ImmutableArray<TResult>.Empty;
return [];

var builder = new TResult[array.Length];

Expand All @@ -456,7 +456,7 @@
{
if (source.Length == 0)
{
return new ValueTask<ImmutableArray<TResult>>(ImmutableArray<TResult>.Empty);
return new ValueTask<ImmutableArray<TResult>>([]);
}

if (source.Length == 1)
Expand Down Expand Up @@ -489,19 +489,19 @@
switch (self.Length)
{
case 0:
return ImmutableArray<TResult>.Empty;
return [];

case 1:
return ImmutableArray.Create(map(self[0], other[0]));
return [map(self[0], other[0])];

case 2:
return ImmutableArray.Create(map(self[0], other[0]), map(self[1], other[1]));
return [map(self[0], other[0]), map(self[1], other[1])];

case 3:
return ImmutableArray.Create(map(self[0], other[0]), map(self[1], other[1]), map(self[2], other[2]));
return [map(self[0], other[0]), map(self[1], other[1]), map(self[2], other[2])];

case 4:
return ImmutableArray.Create(map(self[0], other[0]), map(self[1], other[1]), map(self[2], other[2]), map(self[3], other[3]));
return [map(self[0], other[0]), map(self[1], other[1]), map(self[2], other[2]), map(self[3], other[3])];

default:
var builder = new TResult[self.Length];
Expand All @@ -519,15 +519,15 @@
Debug.Assert(self.Length == other.Length);
if (self.IsEmpty)
{
return ImmutableArray<TResult>.Empty;
return [];
}

var builder = ArrayBuilder<TResult>.GetInstance(self.Length);
var builder = new FixedSizeArrayBuilder<TResult>(self.Length);
for (int i = 0; i < self.Length; i++)
{
builder.Add(map(self[i], other[i], i, arg));
}
return builder.ToImmutableAndFree();
return builder.MoveToImmutable();
}

/// <summary>
Expand Down Expand Up @@ -611,7 +611,7 @@
else
{
Debug.Assert(none);
return ImmutableArray<T>.Empty;
return [];
}
}

Expand Down Expand Up @@ -795,7 +795,7 @@
/// </summary>
public static ImmutableArray<T> NullToEmpty<T>(this ImmutableArray<T> array)
{
return array.IsDefault ? ImmutableArray<T>.Empty : array;
return array.IsDefault ? [] : array;
}

/// <summary>
Expand All @@ -804,7 +804,7 @@
public static ImmutableArray<T> NullToEmpty<T>(this ImmutableArray<T>? array)
=> array switch
{
null or { IsDefault: true } => ImmutableArray<T>.Empty,
null or { IsDefault: true } => [],
{ } underlying => underlying
};

Expand Down Expand Up @@ -862,7 +862,7 @@
{
if (dictionary.Count == 0)
{
return ImmutableArray<TValue>.Empty;
return [];
}

var builder = ArrayBuilder<TValue>.GetInstance();
Expand Down Expand Up @@ -909,13 +909,13 @@
return ImmutableCollectionsMarshal.AsImmutableArray(builder);
}

internal static ImmutableArray<T> Concat<T>(this ImmutableArray<T> first, ImmutableArray<T> second, ImmutableArray<T> third, ImmutableArray<T> fourth)

Check failure on line 912 in src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs

View check run for this annotation

Azure Pipelines / roslyn-CI (Correctness Correctness_Analyzers)

src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs#L912

src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs(912,35): error CS1002: (NETCORE_ENGINEERING_TELEMETRY=Build) ; expected

Check failure on line 912 in src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs

View check run for this annotation

Azure Pipelines / roslyn-CI (Correctness Correctness_Analyzers)

src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs#L912

src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs(912,35): error CS1513: (NETCORE_ENGINEERING_TELEMETRY=Build) } expected

Check failure on line 912 in src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs

View check run for this annotation

Azure Pipelines / roslyn-CI (Unix_Build Build_Unix_Debug)

src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs#L912

src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs(912,35): error CS1002: (NETCORE_ENGINEERING_TELEMETRY=Build) ; expected

Check failure on line 912 in src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs

View check run for this annotation

Azure Pipelines / roslyn-CI (Unix_Build Build_Unix_Debug)

src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs#L912

src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs(912,35): error CS1513: (NETCORE_ENGINEERING_TELEMETRY=Build) } expected

Check failure on line 912 in src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs

View check run for this annotation

Azure Pipelines / roslyn-CI

src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs#L912

src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs(912,35): error CS1002: (NETCORE_ENGINEERING_TELEMETRY=Build) ; expected

Check failure on line 912 in src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs

View check run for this annotation

Azure Pipelines / roslyn-CI

src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs#L912

src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs(912,35): error CS1513: (NETCORE_ENGINEERING_TELEMETRY=Build) } expected
{
var builder = new T[first.Length + second.Length + third.Length + fourth.Length];
var index = 0;

foreach (var item in first)
{

Check failure on line 918 in src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs

View check run for this annotation

Azure Pipelines / roslyn-CI (Correctness Correctness_Analyzers)

src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs#L918

src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs(918,9): error CS8803: (NETCORE_ENGINEERING_TELEMETRY=Build) Top-level statements must precede namespace and type declarations.

Check failure on line 918 in src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs

View check run for this annotation

Azure Pipelines / roslyn-CI (Correctness Correctness_Analyzers)

src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs#L918

src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs(918,9): error CS0106: (NETCORE_ENGINEERING_TELEMETRY=Build) The modifier 'internal' is not valid for this item

Check failure on line 918 in src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs

View check run for this annotation

Azure Pipelines / roslyn-CI (Unix_Build Build_Unix_Debug)

src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs#L918

src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs(918,9): error CS8803: (NETCORE_ENGINEERING_TELEMETRY=Build) Top-level statements must precede namespace and type declarations.

Check failure on line 918 in src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs

View check run for this annotation

Azure Pipelines / roslyn-CI (Unix_Build Build_Unix_Debug)

src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs#L918

src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs(918,9): error CS0106: (NETCORE_ENGINEERING_TELEMETRY=Build) The modifier 'internal' is not valid for this item

Check failure on line 918 in src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs

View check run for this annotation

Azure Pipelines / roslyn-CI

src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs#L918

src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs(918,9): error CS8803: (NETCORE_ENGINEERING_TELEMETRY=Build) Top-level statements must precede namespace and type declarations.

Check failure on line 918 in src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs

View check run for this annotation

Azure Pipelines / roslyn-CI

src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs#L918

src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs(918,9): error CS0106: (NETCORE_ENGINEERING_TELEMETRY=Build) The modifier 'internal' is not valid for this item
builder[index++] = item;
}

Expand Down Expand Up @@ -972,7 +972,7 @@

internal static ImmutableArray<T> Concat<T>(this ImmutableArray<T> first, ImmutableArray<T> second, ImmutableArray<T> third, ImmutableArray<T> fourth, ImmutableArray<T> fifth, ImmutableArray<T> sixth)
{
var builder = new T[first.Length + second.Length + third.Length + fourth.Length + fifth.Length + sixth.Length];

Check failure on line 975 in src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs

View check run for this annotation

Azure Pipelines / roslyn-CI (Correctness Correctness_Analyzers)

src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs#L975

src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs(975,9): error CS0106: (NETCORE_ENGINEERING_TELEMETRY=Build) The modifier 'internal' is not valid for this item

Check failure on line 975 in src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs

View check run for this annotation

Azure Pipelines / roslyn-CI (Unix_Build Build_Unix_Debug)

src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs#L975

src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs(975,9): error CS0106: (NETCORE_ENGINEERING_TELEMETRY=Build) The modifier 'internal' is not valid for this item
var index = 0;

foreach (var item in first)
Expand Down Expand Up @@ -1181,7 +1181,7 @@
{
TNamespaceOrTypeSymbol symbol = (TNamespaceOrTypeSymbol)value;
return symbol is TNamespaceSymbol
? ImmutableArray.Create(symbol)
? [symbol]
: ImmutableArray<TNamespaceOrTypeSymbol>.CastUp(ImmutableArray.Create((TNamedTypeSymbol)symbol));
}
}
Expand Down Expand Up @@ -1230,7 +1230,7 @@
Debug.Assert(count < members.Length);

if (count == 0)
return ImmutableArray<TNamedTypeSymbol>.Empty;
return [];

var builder = ArrayBuilder<TNamedTypeSymbol>.GetInstance(count);
foreach (var member in members)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<Import_RootNamespace>Microsoft.CodeAnalysis.Collections</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Extensions\FixedSizeArrayBuilder.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Segmented\ImmutableSegmentedDictionary.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Segmented\ImmutableSegmentedDictionary`2+Builder+KeyCollection.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Segmented\ImmutableSegmentedDictionary`2+Builder+PrivateMarshal.cs" />
Expand Down Expand Up @@ -92,4 +93,4 @@
<ItemGroup Condition="'$(DefaultLanguageSourceExtension)' != '' AND '$(BuildingInsideVisualStudio)' != 'true'">
<ExpectedCompile Include="$(MSBuildThisFileDirectory)**\*$(DefaultLanguageSourceExtension)" />
</ItemGroup>
</Project>
</Project>
6 changes: 3 additions & 3 deletions src/Dependencies/Collections/OneOrMany.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Roslyn.Utilities
[DebuggerTypeProxy(typeof(OneOrMany<>.DebuggerProxy))]
internal readonly struct OneOrMany<T>
{
public static readonly OneOrMany<T> Empty = new OneOrMany<T>(ImmutableArray<T>.Empty);
public static readonly OneOrMany<T> Empty = new OneOrMany<T>([]);

private readonly T? _one;
private readonly ImmutableArray<T> _many;
Expand Down Expand Up @@ -183,7 +183,7 @@ public bool Any<TArg>(Func<T, TArg, bool> predicate, TArg arg)
=> HasOneItem ? predicate(_one, arg) : _many.Any(predicate, arg);

public ImmutableArray<T> ToImmutable()
=> HasOneItem ? ImmutableArray.Create(_one) : _many;
=> HasOneItem ? [_one] : _many;

public T[] ToArray()
=> HasOneItem ? new[] { _one } : _many.ToArray();
Expand Down Expand Up @@ -270,7 +270,7 @@ public static OneOrMany<T> Create<T>(T one)
=> new OneOrMany<T>(one);

public static OneOrMany<T> Create<T>(T one, T two)
=> new OneOrMany<T>(ImmutableArray.Create(one, two));
=> new OneOrMany<T>([one, two]);

public static OneOrMany<T> OneOrNone<T>(T? one)
=> one is null ? OneOrMany<T>.Empty : new OneOrMany<T>(one);
Expand Down
Loading
Loading