diff --git a/MoreLinq.Test/PartitionTest.cs b/MoreLinq.Test/PartitionTest.cs index cdc4ac19c..2883885c1 100644 --- a/MoreLinq.Test/PartitionTest.cs +++ b/MoreLinq.Test/PartitionTest.cs @@ -15,6 +15,8 @@ // limitations under the License. #endregion +#nullable enable + namespace MoreLinq.Test { using System; diff --git a/MoreLinq/Partition.cs b/MoreLinq/Partition.cs index 2265f96ec..b5b113c72 100644 --- a/MoreLinq/Partition.cs +++ b/MoreLinq/Partition.cs @@ -177,7 +177,8 @@ public static TResult Partition(this IEnumerable, IEnumerable>, TResult> resultSelector) { if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - return PartitionImpl(source, 1, key, key2: default!, key3: default!, comparer, + + return PartitionImpl(source, 1, key, key2: default, key3: default, comparer, (a, _, _, rest) => resultSelector(a, rest)); } @@ -235,8 +236,9 @@ public static TResult Partition(this IEnumerable, IEnumerable, IEnumerable>, TResult> resultSelector) { if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - return PartitionImpl(source, 2, key1, key2, key3: default!, comparer, - (a, b, _, rest) => resultSelector(a, b, rest)); + + return PartitionImpl(source, 2, key1, key2, key3: default, comparer, + (a, b, c, rest) => resultSelector(a, b, rest)); } /// @@ -296,7 +298,7 @@ public static TResult Partition(this IEnumerable(IEnumerable> source, - int count, TKey key1, TKey key2, TKey key3, IEqualityComparer? comparer, + int count, TKey? key1, TKey? key2, TKey? key3, IEqualityComparer? comparer, Func, IEnumerable, IEnumerable, IEnumerable>, TResult> resultSelector) { Debug.Assert(count is > 0 and <= 3); @@ -317,9 +319,9 @@ static TResult PartitionImpl(IEnumerable 0 && comparer.Equals(e.Key, key1) ? 0 - : count > 1 && comparer.Equals(e.Key, key2) ? 1 - : count > 2 && comparer.Equals(e.Key, key3) ? 2 + var i = count > 0 && comparer.Equals(e.Key, key1!) ? 0 + : count > 1 && comparer.Equals(e.Key, key2!) ? 1 + : count > 2 && comparer.Equals(e.Key, key3!) ? 2 : -1; if (i < 0)