Skip to content

Commit 847a480

Browse files
Merge remote-tracking branch 'origin/master' into features/range-exclude
# Conflicts: # Source/SuperLinq/PublicAPI/net6.0/PublicAPI.Unshipped.txt # Source/SuperLinq/PublicAPI/net7.0/PublicAPI.Unshipped.txt # Source/SuperLinq/PublicAPI/net8.0/PublicAPI.Unshipped.txt # Source/SuperLinq/PublicAPI/net9.0/PublicAPI.Unshipped.txt # Source/SuperLinq/PublicAPI/netcoreapp3.1/PublicAPI.Unshipped.txt
2 parents 918b322 + 886ca78 commit 847a480

22 files changed

+381
-348
lines changed

Source/SuperLinq.Async/PublicAPI/net6.0/PublicAPI.Unshipped.txt

+23-23
Large diffs are not rendered by default.

Source/SuperLinq.Async/PublicAPI/net7.0/PublicAPI.Unshipped.txt

+23-23
Large diffs are not rendered by default.

Source/SuperLinq.Async/PublicAPI/net8.0/PublicAPI.Unshipped.txt

+23-23
Large diffs are not rendered by default.

Source/SuperLinq.Async/PublicAPI/net9.0/PublicAPI.Unshipped.txt

+23-23
Large diffs are not rendered by default.

Source/SuperLinq.Async/PublicAPI/netcoreapp3.1/PublicAPI.Unshipped.txt

+23-23
Large diffs are not rendered by default.

Source/SuperLinq/Batch.Buffered.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static partial class SuperEnumerable
4545
public static IEnumerable<TResult> Batch<TSource, TResult>(
4646
this IEnumerable<TSource> source,
4747
int size,
48-
Func<ArraySegment<TSource>, TResult> resultSelector)
48+
ReadOnlySpanFunc<TSource, TResult> resultSelector)
4949
{
5050
ArgumentNullException.ThrowIfNull(source);
5151
ArgumentNullException.ThrowIfNull(resultSelector);
@@ -94,7 +94,7 @@ public static IEnumerable<TResult> Batch<TSource, TResult>(
9494
public static IEnumerable<TResult> Batch<TSource, TResult>(
9595
this IEnumerable<TSource> source,
9696
TSource[] array,
97-
Func<ArraySegment<TSource>, TResult> resultSelector)
97+
ReadOnlySpanFunc<TSource, TResult> resultSelector)
9898
{
9999
ArgumentNullException.ThrowIfNull(source);
100100
ArgumentNullException.ThrowIfNull(array);
@@ -149,7 +149,7 @@ public static IEnumerable<TResult> Batch<TSource, TResult>(
149149
this IEnumerable<TSource> source,
150150
TSource[] array,
151151
int size,
152-
Func<ArraySegment<TSource>, TResult> resultSelector)
152+
ReadOnlySpanFunc<TSource, TResult> resultSelector)
153153
{
154154
ArgumentNullException.ThrowIfNull(source);
155155
ArgumentNullException.ThrowIfNull(array);
@@ -164,7 +164,7 @@ private static IEnumerable<TResult> BatchImpl<TSource, TResult>(
164164
IEnumerable<TSource> source,
165165
TSource[] array,
166166
int size,
167-
Func<ArraySegment<TSource>, TResult> resultSelector)
167+
ReadOnlySpanFunc<TSource, TResult> resultSelector)
168168
{
169169
if (source is ICollection<TSource> coll)
170170
{
@@ -174,7 +174,7 @@ private static IEnumerable<TResult> BatchImpl<TSource, TResult>(
174174
if (coll.Count <= size)
175175
{
176176
coll.CopyTo(array, 0);
177-
yield return resultSelector(new ArraySegment<TSource>(array, 0, coll.Count));
177+
yield return resultSelector(new ReadOnlySpan<TSource>(array, 0, coll.Count));
178178
yield break;
179179
}
180180
}
@@ -185,12 +185,12 @@ private static IEnumerable<TResult> BatchImpl<TSource, TResult>(
185185
array[n++] = item;
186186
if (n == size)
187187
{
188-
yield return resultSelector(new ArraySegment<TSource>(array, 0, n));
188+
yield return resultSelector(new ReadOnlySpan<TSource>(array, 0, n));
189189
n = 0;
190190
}
191191
}
192192

193193
if (n != 0)
194-
yield return resultSelector(new ArraySegment<TSource>(array, 0, n));
194+
yield return resultSelector(new ReadOnlySpan<TSource>(array, 0, n));
195195
}
196196
}

Source/SuperLinq/PublicAPI/net6.0/PublicAPI.Unshipped.txt

+35-34
Large diffs are not rendered by default.

Source/SuperLinq/PublicAPI/net7.0/PublicAPI.Unshipped.txt

+35-34
Large diffs are not rendered by default.

Source/SuperLinq/PublicAPI/net8.0/PublicAPI.Unshipped.txt

+35-34
Large diffs are not rendered by default.

Source/SuperLinq/PublicAPI/net9.0/PublicAPI.Unshipped.txt

+35-34
Large diffs are not rendered by default.

Source/SuperLinq/PublicAPI/netcoreapp3.1/PublicAPI.Unshipped.txt

+35-34
Large diffs are not rendered by default.

Source/SuperLinq/SuperEnumerable.cs

+20-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,29 @@
33
namespace SuperLinq;
44

55
/// <summary>
6-
/// Provides a set of static methods for querying objects that
7-
/// implement <see cref="IEnumerable{T}" />.
6+
/// Provides a set of static methods for querying objects that
7+
/// implement <see cref="IEnumerable{T}" />.
88
/// </summary>
99
public static partial class SuperEnumerable
1010
{
11+
/// <summary>
12+
/// Delegate that receives a <see cref="ReadOnlySpan{T}">ReadOnlySpan&lt;TSource&gt;</see>
13+
/// and outputs a value of type <see langword="out"/> <typeparamref name="TResult"/>.
14+
/// </summary>
15+
/// <typeparam name="TSource">
16+
/// The type of items in the <see cref="ReadOnlySpan{T}">ReadOnlySpan</see>.
17+
/// </typeparam>
18+
/// <typeparam name="TResult">
19+
/// The type of the returned value.
20+
/// </typeparam>
21+
/// <param name="span">
22+
/// The parameter of the method that this delegate encapsulates.
23+
/// </param>
24+
/// <returns>
25+
/// Value of type <see langword="out"/> <typeparamref name="TResult"/>.
26+
/// </returns>
27+
public delegate TResult ReadOnlySpanFunc<TSource, out TResult>(ReadOnlySpan<TSource> span);
28+
1129
[ExcludeFromCodeCoverage]
1230
internal static int? TryGetCollectionCount<T>(this IEnumerable<T> source)
1331
{

Source/SuperLinq/Window.Buffered.Impl.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ private static IEnumerable<TResult> WindowImpl<TSource, TResult>(
88
TSource[] array,
99
int size,
1010
WindowType type,
11-
Func<ArraySegment<TSource>, TResult> projector)
11+
ReadOnlySpanFunc<TSource, TResult> projector)
1212
{
1313
var n = 0;
1414

@@ -18,14 +18,14 @@ private static IEnumerable<TResult> WindowImpl<TSource, TResult>(
1818
{
1919
array[n++] = i;
2020
if (type == WindowType.Right || n == size)
21-
yield return projector(new ArraySegment<TSource>(array, 0, n));
21+
yield return projector(new ReadOnlySpan<TSource>(array, 0, n));
2222
}
2323
else
2424
{
2525
array.AsSpan()[1..n].CopyTo(array);
2626
array[n - 1] = i;
2727

28-
yield return projector(new ArraySegment<TSource>(array, 0, n));
28+
yield return projector(new ReadOnlySpan<TSource>(array, 0, n));
2929
}
3030
}
3131

Source/SuperLinq/Window.Buffered.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static partial class SuperEnumerable
4747
public static IEnumerable<TResult> Window<TSource, TResult>(
4848
this IEnumerable<TSource> source,
4949
int size,
50-
Func<ArraySegment<TSource>, TResult> selector)
50+
ReadOnlySpanFunc<TSource, TResult> selector)
5151
{
5252
ArgumentNullException.ThrowIfNull(source);
5353
ArgumentNullException.ThrowIfNull(selector);
@@ -98,7 +98,7 @@ public static IEnumerable<TResult> Window<TSource, TResult>(
9898
public static IEnumerable<TResult> Window<TSource, TResult>(
9999
this IEnumerable<TSource> source,
100100
TSource[] array,
101-
Func<ArraySegment<TSource>, TResult> selector)
101+
ReadOnlySpanFunc<TSource, TResult> selector)
102102
{
103103
ArgumentNullException.ThrowIfNull(source);
104104
ArgumentNullException.ThrowIfNull(array);
@@ -157,7 +157,7 @@ public static IEnumerable<TResult> Window<TSource, TResult>(
157157
this IEnumerable<TSource> source,
158158
TSource[] array,
159159
int size,
160-
Func<ArraySegment<TSource>, TResult> selector)
160+
ReadOnlySpanFunc<TSource, TResult> selector)
161161
{
162162
ArgumentNullException.ThrowIfNull(source);
163163
ArgumentNullException.ThrowIfNull(array);

Source/SuperLinq/WindowLeft.Buffered.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static partial class SuperEnumerable
4545
public static IEnumerable<TResult> WindowLeft<TSource, TResult>(
4646
this IEnumerable<TSource> source,
4747
int size,
48-
Func<ArraySegment<TSource>, TResult> selector)
48+
ReadOnlySpanFunc<TSource, TResult> selector)
4949
{
5050
ArgumentNullException.ThrowIfNull(source);
5151
ArgumentNullException.ThrowIfNull(selector);
@@ -94,7 +94,7 @@ public static IEnumerable<TResult> WindowLeft<TSource, TResult>(
9494
public static IEnumerable<TResult> WindowLeft<TSource, TResult>(
9595
this IEnumerable<TSource> source,
9696
TSource[] array,
97-
Func<ArraySegment<TSource>, TResult> selector)
97+
ReadOnlySpanFunc<TSource, TResult> selector)
9898
{
9999
ArgumentNullException.ThrowIfNull(source);
100100
ArgumentNullException.ThrowIfNull(array);
@@ -152,7 +152,7 @@ public static IEnumerable<TResult> WindowLeft<TSource, TResult>(
152152
this IEnumerable<TSource> source,
153153
TSource[] array,
154154
int size,
155-
Func<ArraySegment<TSource>, TResult> selector)
155+
ReadOnlySpanFunc<TSource, TResult> selector)
156156
{
157157
ArgumentNullException.ThrowIfNull(source);
158158
ArgumentNullException.ThrowIfNull(array);

Source/SuperLinq/WindowRight.Buffered.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static partial class SuperEnumerable
4545
public static IEnumerable<TResult> WindowRight<TSource, TResult>(
4646
this IEnumerable<TSource> source,
4747
int size,
48-
Func<ArraySegment<TSource>, TResult> selector)
48+
ReadOnlySpanFunc<TSource, TResult> selector)
4949
{
5050
ArgumentNullException.ThrowIfNull(source);
5151
ArgumentNullException.ThrowIfNull(selector);
@@ -94,7 +94,7 @@ public static IEnumerable<TResult> WindowRight<TSource, TResult>(
9494
public static IEnumerable<TResult> WindowRight<TSource, TResult>(
9595
this IEnumerable<TSource> source,
9696
TSource[] array,
97-
Func<ArraySegment<TSource>, TResult> selector)
97+
ReadOnlySpanFunc<TSource, TResult> selector)
9898
{
9999
ArgumentNullException.ThrowIfNull(source);
100100
ArgumentNullException.ThrowIfNull(array);
@@ -151,7 +151,7 @@ public static IEnumerable<TResult> WindowRight<TSource, TResult>(
151151
this IEnumerable<TSource> source,
152152
TSource[] array,
153153
int size,
154-
Func<ArraySegment<TSource>, TResult> selector)
154+
ReadOnlySpanFunc<TSource, TResult> selector)
155155
{
156156
ArgumentNullException.ThrowIfNull(source);
157157
ArgumentNullException.ThrowIfNull(array);

Tests/SuperLinq.Test/BatchTest.cs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Test;
1+
namespace Test;
22

33
public class BatchTest
44
{
@@ -9,11 +9,11 @@ public void BatchIsLazy()
99
_ = new BreakingSequence<int>().Buffer(1);
1010

1111
_ = new BreakingSequence<int>()
12-
.Batch(1, BreakingFunc.Of<ArraySegment<int>, int>());
12+
.Batch(1, BreakingReadOnlySpanFunc.Of<int, int>());
1313
_ = new BreakingSequence<int>()
14-
.Batch(new int[2], BreakingFunc.Of<ArraySegment<int>, int>());
14+
.Batch(new int[2], BreakingReadOnlySpanFunc.Of<int, int>());
1515
_ = new BreakingSequence<int>()
16-
.Batch(new int[2], 1, BreakingFunc.Of<ArraySegment<int>, int>());
16+
.Batch(new int[2], 1, BreakingReadOnlySpanFunc.Of<int, int>());
1717
}
1818

1919
[Fact]
@@ -25,18 +25,18 @@ public void BatchValidatesSize()
2525

2626
_ = Assert.Throws<ArgumentOutOfRangeException>("size",
2727
() => new BreakingSequence<int>()
28-
.Batch(0, BreakingFunc.Of<ArraySegment<int>, int>()));
28+
.Batch(0, BreakingReadOnlySpanFunc.Of<int, int>()));
2929

3030
_ = Assert.Throws<ArgumentOutOfRangeException>("size",
3131
() => new BreakingSequence<int>()
32-
.Batch([], 0, BreakingFunc.Of<ArraySegment<int>, int>()));
32+
.Batch([], 0, BreakingReadOnlySpanFunc.Of<int, int>()));
3333

3434
_ = Assert.Throws<ArgumentOutOfRangeException>("size",
3535
() => new BreakingSequence<int>()
36-
.Batch(new int[5], 6, BreakingFunc.Of<ArraySegment<int>, int>()));
36+
.Batch(new int[5], 6, BreakingReadOnlySpanFunc.Of<int, int>()));
3737

3838
_ = new BreakingSequence<int>()
39-
.Batch(new int[5], 5, BreakingFunc.Of<ArraySegment<int>, int>());
39+
.Batch(new int[5], 5, BreakingReadOnlySpanFunc.Of<int, int>());
4040
}
4141

4242
public static IEnumerable<object[]> GetFourElementSequences() =>
@@ -122,9 +122,9 @@ private static IEnumerable<IList<T>> GetBatches<T>(
122122
method switch
123123
{
124124
BatchMethod.Traditional => seq.Batch(size),
125-
BatchMethod.BufferSize => seq.Batch(size, arr => arr.ToList()),
126-
BatchMethod.BufferArray => seq.Batch(new T[size], arr => arr.ToList()),
127-
BatchMethod.BufferSizeArray => seq.Batch(new T[size + 10], size, arr => arr.ToList()),
125+
BatchMethod.BufferSize => seq.Batch(size, arr => arr.ToArray()),
126+
BatchMethod.BufferArray => seq.Batch(new T[size], arr => arr.ToArray()),
127+
BatchMethod.BufferSizeArray => seq.Batch(new T[size + 10], size, arr => arr.ToArray()),
128128
_ => throw new NotSupportedException(),
129129
};
130130

Tests/SuperLinq.Test/BreakingFunc.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Test;
1+
namespace Test;
22

33
/// <summary>
44
/// Functions which throw NotImplementedException if they're ever called.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Test;
2+
3+
/// <summary>
4+
/// Functions which throw NotImplementedException if they're ever called.
5+
/// </summary>
6+
internal static class BreakingReadOnlySpanFunc
7+
{
8+
internal static SuperEnumerable.ReadOnlySpanFunc<T, TResult> Of<T, TResult>() =>
9+
t => throw new TestException();
10+
}

Tests/SuperLinq.Test/WindowLeftTest.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ public partial class WindowLeftTest
66
public void WindowLeftIsLazy()
77
{
88
_ = new BreakingSequence<int>().WindowLeft(1);
9-
_ = new BreakingSequence<int>().WindowLeft(1, BreakingFunc.Of<ArraySegment<int>, int>());
10-
_ = new BreakingSequence<int>().WindowLeft(new int[3], BreakingFunc.Of<ArraySegment<int>, int>());
11-
_ = new BreakingSequence<int>().WindowLeft(new int[3], 1, BreakingFunc.Of<ArraySegment<int>, int>());
9+
_ = new BreakingSequence<int>().WindowLeft(1, BreakingReadOnlySpanFunc.Of<int, int>());
10+
_ = new BreakingSequence<int>().WindowLeft(new int[3], BreakingReadOnlySpanFunc.Of<int, int>());
11+
_ = new BreakingSequence<int>().WindowLeft(new int[3], 1, BreakingReadOnlySpanFunc.Of<int, int>());
1212
}
1313

1414
[Fact]
@@ -18,16 +18,16 @@ public void WindowLeftNegativeWindowSizeException()
1818
new BreakingSequence<int>().WindowLeft(-5));
1919

2020
_ = Assert.Throws<ArgumentOutOfRangeException>(() =>
21-
new BreakingSequence<int>().WindowLeft(-5, SuperEnumerable.Identity));
21+
new BreakingSequence<int>().WindowLeft(-5, BreakingReadOnlySpanFunc.Of<int, int>()));
2222

2323
_ = Assert.Throws<ArgumentOutOfRangeException>(() =>
24-
new BreakingSequence<int>().WindowLeft([], -5, SuperEnumerable.Identity));
24+
new BreakingSequence<int>().WindowLeft([], -5, BreakingReadOnlySpanFunc.Of<int, int>()));
2525

2626
_ = Assert.Throws<ArgumentOutOfRangeException>(() =>
27-
new BreakingSequence<int>().WindowLeft(new int[5], 6, SuperEnumerable.Identity));
27+
new BreakingSequence<int>().WindowLeft(new int[5], 6, BreakingReadOnlySpanFunc.Of<int, int>()));
2828

2929
_ = new BreakingSequence<int>()
30-
.WindowLeft(new int[5], 5, SuperEnumerable.Identity);
30+
.WindowLeft(new int[5], 5, BreakingReadOnlySpanFunc.Of<int, int>());
3131
}
3232

3333
public static IEnumerable<object[]> GetThreeElementSequences() =>
@@ -113,9 +113,9 @@ private static IEnumerable<IList<T>> GetWindows<T>(
113113
method switch
114114
{
115115
WindowMethod.Traditional => seq.WindowLeft(size),
116-
WindowMethod.BufferSize => seq.WindowLeft(size, arr => arr.ToList()),
117-
WindowMethod.BufferArray => seq.WindowLeft(new T[size], arr => arr.ToList()),
118-
WindowMethod.BufferSizeArray => seq.WindowLeft(new T[size + 10], size, arr => arr.ToList()),
116+
WindowMethod.BufferSize => seq.WindowLeft(size, arr => arr.ToArray()),
117+
WindowMethod.BufferArray => seq.WindowLeft(new T[size], arr => arr.ToArray()),
118+
WindowMethod.BufferSizeArray => seq.WindowLeft(new T[size + 10], size, arr => arr.ToArray()),
119119
_ => throw new NotSupportedException(),
120120
};
121121

Tests/SuperLinq.Test/WindowRightTest.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ public partial class WindowRightTest
66
public void WindowRightIsLazy()
77
{
88
_ = new BreakingSequence<int>().WindowRight(1);
9-
_ = new BreakingSequence<int>().WindowRight(1, BreakingFunc.Of<ArraySegment<int>, int>());
10-
_ = new BreakingSequence<int>().WindowRight(new int[3], BreakingFunc.Of<ArraySegment<int>, int>());
11-
_ = new BreakingSequence<int>().WindowRight(new int[3], 1, BreakingFunc.Of<ArraySegment<int>, int>());
9+
_ = new BreakingSequence<int>().WindowRight(1, BreakingReadOnlySpanFunc.Of<int, int>());
10+
_ = new BreakingSequence<int>().WindowRight(new int[3], BreakingReadOnlySpanFunc.Of<int, int>());
11+
_ = new BreakingSequence<int>().WindowRight(new int[3], 1, BreakingReadOnlySpanFunc.Of<int, int>());
1212
}
1313

1414
[Fact]
@@ -20,16 +20,16 @@ public void WindowRightNegativeWindowSizeException()
2020
new BreakingSequence<int>().WindowRight(-5));
2121

2222
_ = Assert.Throws<ArgumentOutOfRangeException>(() =>
23-
new BreakingSequence<int>().WindowRight(-5, SuperEnumerable.Identity));
23+
new BreakingSequence<int>().WindowRight(-5, BreakingReadOnlySpanFunc.Of<int, int>()));
2424

2525
_ = Assert.Throws<ArgumentOutOfRangeException>(() =>
26-
new BreakingSequence<int>().WindowRight([], -5, SuperEnumerable.Identity));
26+
new BreakingSequence<int>().WindowRight([], -5, BreakingReadOnlySpanFunc.Of<int, int>()));
2727

2828
_ = Assert.Throws<ArgumentOutOfRangeException>(() =>
29-
new BreakingSequence<int>().WindowRight(new int[5], 6, SuperEnumerable.Identity));
29+
new BreakingSequence<int>().WindowRight(new int[5], 6, BreakingReadOnlySpanFunc.Of<int, int>()));
3030

3131
_ = new BreakingSequence<int>()
32-
.WindowRight(new int[5], 5, SuperEnumerable.Identity);
32+
.WindowRight(new int[5], 5, BreakingReadOnlySpanFunc.Of<int, int>());
3333
}
3434

3535
public static IEnumerable<object[]> GetThreeElementSequences() =>
@@ -115,9 +115,9 @@ private static IEnumerable<IList<T>> GetWindows<T>(
115115
method switch
116116
{
117117
WindowMethod.Traditional => seq.WindowRight(size),
118-
WindowMethod.BufferSize => seq.WindowRight(size, arr => arr.ToList()),
119-
WindowMethod.BufferArray => seq.WindowRight(new T[size], arr => arr.ToList()),
120-
WindowMethod.BufferSizeArray => seq.WindowRight(new T[size + 10], size, arr => arr.ToList()),
118+
WindowMethod.BufferSize => seq.WindowRight(size, arr => arr.ToArray()),
119+
WindowMethod.BufferArray => seq.WindowRight(new T[size], arr => arr.ToArray()),
120+
WindowMethod.BufferSizeArray => seq.WindowRight(new T[size + 10], size, arr => arr.ToArray()),
121121
_ => throw new NotSupportedException(),
122122
};
123123

0 commit comments

Comments
 (0)