Skip to content

Commit

Permalink
Fix "ZipLongest" signatures with more honest nullable annotations
Browse files Browse the repository at this point in the history
This is a squashed merge of PR #900 that adds to #803.
  • Loading branch information
viceroypenguin authored Dec 17, 2022
1 parent eeddf4d commit 625ee56
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
16 changes: 9 additions & 7 deletions MoreLinq.Test/ZipLongestTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// limitations under the License.
#endregion

#nullable enable

namespace MoreLinq.Test
{
using System;
Expand All @@ -31,13 +33,13 @@ public class ZipLongestTest
public static readonly IEnumerable<ITestCaseData> TestData =
from e in new[]
{
new { A = Seq<int>( ), B = Seq("foo", "bar", "baz"), Result = Seq((0, "foo"), (0, "bar"), (0, "baz")) },
new { A = Seq(1 ), B = Seq("foo", "bar", "baz"), Result = Seq((1, "foo"), (0, "bar"), (0, "baz")) },
new { A = Seq(1, 2 ), B = Seq("foo", "bar", "baz"), Result = Seq((1, "foo"), (2, "bar"), (0, "baz")) },
new { A = Seq(1, 2, 3), B = Seq<string>( ), Result = Seq((1, null ), (2, null ), (3, (string) null)) },
new { A = Seq(1, 2, 3), B = Seq("foo" ), Result = Seq((1, "foo"), (2, null ), (3, null )) },
new { A = Seq(1, 2, 3), B = Seq("foo", "bar" ), Result = Seq((1, "foo"), (2, "bar"), (3, null )) },
new { A = Seq(1, 2, 3), B = Seq("foo", "bar", "baz"), Result = Seq((1, "foo"), (2, "bar"), (3, "baz")) },
new { A = Seq<int>( ), B = Seq("foo", "bar", "baz"), Result = Seq<(int, string?)>((0, "foo"), (0, "bar"), (0, "baz")) },
new { A = Seq(1 ), B = Seq("foo", "bar", "baz"), Result = Seq<(int, string?)>((1, "foo"), (0, "bar"), (0, "baz")) },
new { A = Seq(1, 2 ), B = Seq("foo", "bar", "baz"), Result = Seq<(int, string?)>((1, "foo"), (2, "bar"), (0, "baz")) },
new { A = Seq(1, 2, 3), B = Seq<string>( ), Result = Seq<(int, string?)>((1, null ), (2, null ), (3, null )) },
new { A = Seq(1, 2, 3), B = Seq("foo" ), Result = Seq<(int, string?)>((1, "foo"), (2, null ), (3, null )) },
new { A = Seq(1, 2, 3), B = Seq("foo", "bar" ), Result = Seq<(int, string?)>((1, "foo"), (2, "bar"), (3, null )) },
new { A = Seq(1, 2, 3), B = Seq("foo", "bar", "baz"), Result = Seq<(int, string?)>((1, "foo"), (2, "bar"), (3, "baz")) },
}
select new TestCaseData(e.A, e.B)
.Returns(e.Result);
Expand Down
6 changes: 3 additions & 3 deletions MoreLinq/Extensions.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6837,7 +6837,7 @@ public static partial class ZipLongestExtension
public static IEnumerable<TResult> ZipLongest<TFirst, TSecond, TResult>(
this IEnumerable<TFirst> first,
IEnumerable<TSecond> second,
Func<TFirst, TSecond, TResult> resultSelector)
Func<TFirst?, TSecond?, TResult> resultSelector)
=> MoreEnumerable.ZipLongest(first, second, resultSelector);

/// <summary>
Expand Down Expand Up @@ -6883,7 +6883,7 @@ public static IEnumerable<TResult> ZipLongest<T1, T2, T3, TResult>(
this IEnumerable<T1> first,
IEnumerable<T2> second,
IEnumerable<T3> third,
Func<T1, T2, T3, TResult> resultSelector)
Func<T1?, T2?, T3?, TResult> resultSelector)
=> MoreEnumerable.ZipLongest(first, second, third, resultSelector);

/// <summary>
Expand Down Expand Up @@ -6933,7 +6933,7 @@ public static IEnumerable<TResult> ZipLongest<T1, T2, T3, T4, TResult>(
IEnumerable<T2> second,
IEnumerable<T3> third,
IEnumerable<T4> fourth,
Func<T1, T2, T3, T4, TResult> resultSelector)
Func<T1?, T2?, T3?, T4?, TResult> resultSelector)
=> MoreEnumerable.ZipLongest(first, second, third, fourth, resultSelector);

}
Expand Down
6 changes: 3 additions & 3 deletions MoreLinq/ZipLongest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static partial class MoreEnumerable
public static IEnumerable<TResult> ZipLongest<TFirst, TSecond, TResult>(
this IEnumerable<TFirst> first,
IEnumerable<TSecond> second,
Func<TFirst, TSecond, TResult> resultSelector)
Func<TFirst?, TSecond?, TResult> resultSelector)
{
if (first == null) throw new ArgumentNullException(nameof(first));
if (second == null) throw new ArgumentNullException(nameof(second));
Expand Down Expand Up @@ -112,7 +112,7 @@ public static IEnumerable<TResult> ZipLongest<T1, T2, T3, TResult>(
this IEnumerable<T1> first,
IEnumerable<T2> second,
IEnumerable<T3> third,
Func<T1, T2, T3, TResult> resultSelector)
Func<T1?, T2?, T3?, TResult> resultSelector)
{
if (first == null) throw new ArgumentNullException(nameof(first));
if (second == null) throw new ArgumentNullException(nameof(second));
Expand Down Expand Up @@ -169,7 +169,7 @@ public static IEnumerable<TResult> ZipLongest<T1, T2, T3, T4, TResult>(
IEnumerable<T2> second,
IEnumerable<T3> third,
IEnumerable<T4> fourth,
Func<T1, T2, T3, T4, TResult> resultSelector)
Func<T1?, T2?, T3?, T4?, TResult> resultSelector)
{
if (first == null) throw new ArgumentNullException(nameof(first));
if (second == null) throw new ArgumentNullException(nameof(second));
Expand Down

0 comments on commit 625ee56

Please sign in to comment.