diff --git a/.editorconfig b/.editorconfig
index 34d8b9f5..c785362a 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -209,7 +209,6 @@ dotnet_analyzer_diagnostic.category-Style.severity = warning
dotnet_diagnostic.IDE0011.severity = silent # IDE0011: Add braces
dotnet_diagnostic.IDE0046.severity = silent # IDE0046: Convert to conditional expression
-dotnet_diagnostic.IDE0290.severity = none # IDE0290: Use primary constructor
dotnet_diagnostic.IDE0028.severity = none # IDE0028: Simplify collection initialization
dotnet_diagnostic.IDE0305.severity = none # IDE0305: Simplify collection initialization
@@ -241,3 +240,9 @@ dotnet_diagnostic.RS0026.severity = none # RS0026: Do not add multiple public
# Bug in compiler
dotnet_diagnostic.CA1861.severity = none # CA1861: Avoid constant arrays as arguments
+
+# Primary Constructors
+dotnet_diagnostic.CS9107.severity = error # CS9107: Parameter is captured into the state of the enclosing type and its value is also passed to the base constructor
+dotnet_diagnostic.CS9113.severity = error # CS9113: Your class never references the primary constructor
+dotnet_diagnostic.CS9124.severity = error # CS9124: Parameter is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event
+dotnet_diagnostic.CS9179.severity = error # CS9179: Primary constructor parameter is shadowed by a member from base
diff --git a/Directory.Build.props b/Directory.Build.props
index cd5e481d..ef695e4a 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -8,7 +8,7 @@
enable
false
-
+
latest-all
true
diff --git a/Source/SuperLinq.Async/EnumeratorList.cs b/Source/SuperLinq.Async/EnumeratorList.cs
index de982d69..f8015406 100644
--- a/Source/SuperLinq.Async/EnumeratorList.cs
+++ b/Source/SuperLinq.Async/EnumeratorList.cs
@@ -1,9 +1,9 @@
namespace SuperLinq.Async;
-internal sealed class EnumeratorList : IAsyncDisposable
+internal sealed class EnumeratorList(
+ List.Enumerator> iter
+) : IAsyncDisposable
{
- private readonly List.Enumerator> _iter;
-
internal static async ValueTask> Create(IEnumerable> sources, CancellationToken cancellationToken)
{
var list = new List.Enumerator>();
@@ -24,24 +24,19 @@ internal static async ValueTask> Create(IEnumerable.Enumerator> iter)
- {
- _iter = iter;
- }
-
- public int Count => _iter.Count;
+ public int Count => iter.Count;
- public bool Any() => _iter.Count != 0;
+ public bool Any() => iter.Count != 0;
public async ValueTask MoveNext(int i)
{
- while (i < _iter.Count)
+ while (i < iter.Count)
{
- var e = _iter[i];
+ var e = iter[i];
if (await e.MoveNextAsync())
return true;
- _iter.RemoveAt(i);
+ iter.RemoveAt(i);
await e.DisposeAsync();
}
@@ -50,13 +45,13 @@ public async ValueTask MoveNext(int i)
public async ValueTask MoveNextOnce(int i)
{
- if (i < _iter.Count)
+ if (i < iter.Count)
{
- var e = _iter[i];
+ var e = iter[i];
if (await e.MoveNextAsync())
return true;
- _iter.RemoveAt(i);
+ iter.RemoveAt(i);
await e.DisposeAsync();
}
@@ -64,11 +59,11 @@ public async ValueTask MoveNextOnce(int i)
}
public T Current(int i) =>
- _iter[i].Current;
+ iter[i].Current;
public async ValueTask DisposeAsync()
{
- foreach (var e in _iter)
+ foreach (var e in iter)
await e.DisposeAsync();
}
}
diff --git a/Source/SuperLinq.Async/GroupAdjacent.cs b/Source/SuperLinq.Async/GroupAdjacent.cs
index 648eacd4..02fbe41f 100644
--- a/Source/SuperLinq.Async/GroupAdjacent.cs
+++ b/Source/SuperLinq.Async/GroupAdjacent.cs
@@ -297,17 +297,14 @@ private static Grouping CreateGroupAdjacentGrouping : IGrouping
+ private sealed class Grouping(
+ TKey key,
+ IEnumerable members
+ ) : IGrouping
{
- private readonly IEnumerable _members;
+ private readonly IEnumerable _members = members;
- public Grouping(TKey key, IEnumerable members)
- {
- Key = key;
- _members = members;
- }
-
- public TKey Key { get; }
+ public TKey Key { get; } = key;
public IEnumerator GetEnumerator() => _members.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
diff --git a/Source/SuperLinq.Async/Join.MergeJoin.cs b/Source/SuperLinq.Async/Join.MergeJoin.cs
index c15dc4f8..d639fcc0 100644
--- a/Source/SuperLinq.Async/Join.MergeJoin.cs
+++ b/Source/SuperLinq.Async/Join.MergeJoin.cs
@@ -717,15 +717,10 @@ private static async IAsyncEnumerable JoinMerge : IEqualityComparer
+file sealed class ComparerEqualityComparer(
+ IComparer comparer
+) : IEqualityComparer
{
- private readonly IComparer _comparer;
-
- public ComparerEqualityComparer(IComparer comparer)
- {
- _comparer = comparer;
- }
-
- public bool Equals([AllowNull] TKey x, [AllowNull] TKey y) => _comparer.Compare(x, y) == 0;
+ public bool Equals([AllowNull] TKey x, [AllowNull] TKey y) => comparer.Compare(x, y) == 0;
public int GetHashCode([DisallowNull] TKey obj) => ThrowHelper.ThrowNotSupportedException();
}
diff --git a/Source/SuperLinq.Async/Memoize.cs b/Source/SuperLinq.Async/Memoize.cs
index c9c63108..01c7018e 100644
--- a/Source/SuperLinq.Async/Memoize.cs
+++ b/Source/SuperLinq.Async/Memoize.cs
@@ -32,11 +32,13 @@ public static IAsyncBuffer Memoize(this IAsyncEnumerable(source);
}
- private sealed class EnumerableMemoizedBuffer : IAsyncBuffer
+ private sealed class EnumerableMemoizedBuffer(
+ IAsyncEnumerable source
+ ) : IAsyncBuffer
{
private readonly SemaphoreSlim _lock = new(initialCount: 1);
- private IAsyncEnumerable? _source;
+ private IAsyncEnumerable? _source = source;
private IAsyncEnumerator? _enumerator;
private List _buffer = new();
@@ -47,11 +49,6 @@ private sealed class EnumerableMemoizedBuffer : IAsyncBuffer
private bool _disposed;
- public EnumerableMemoizedBuffer(IAsyncEnumerable source)
- {
- _source = source;
- }
-
public int Count => _buffer.Count;
public async ValueTask Reset(CancellationToken cancellationToken = default)
diff --git a/Source/SuperLinq.Async/Publish.cs b/Source/SuperLinq.Async/Publish.cs
index f3302edf..561022f0 100644
--- a/Source/SuperLinq.Async/Publish.cs
+++ b/Source/SuperLinq.Async/Publish.cs
@@ -22,11 +22,13 @@ public static IAsyncBuffer Publish(this IAsyncEnumerable(source);
}
- private sealed class PublishBuffer : IAsyncBuffer
+ private sealed class PublishBuffer(
+ IAsyncEnumerable source
+ ) : IAsyncBuffer
{
private readonly SemaphoreSlim _lock = new(initialCount: 1);
- private IAsyncEnumerable? _source;
+ private IAsyncEnumerable? _source = source;
private IAsyncEnumerator? _enumerator;
private List>? _buffers;
@@ -38,11 +40,6 @@ private sealed class PublishBuffer : IAsyncBuffer
private bool _disposed;
- public PublishBuffer(IAsyncEnumerable source)
- {
- _source = source;
- }
-
public int Count => _buffers?.Count > 0 ? _buffers.Max(x => x.Count) : 0;
public async ValueTask Reset(CancellationToken cancellationToken = default)
diff --git a/Source/SuperLinq.Async/Share.cs b/Source/SuperLinq.Async/Share.cs
index b7a40433..33495099 100644
--- a/Source/SuperLinq.Async/Share.cs
+++ b/Source/SuperLinq.Async/Share.cs
@@ -19,11 +19,13 @@ public static IAsyncBuffer Share(this IAsyncEnumerable(source);
}
- private sealed class SharedBuffer : IAsyncBuffer
+ private sealed class SharedBuffer(
+ IAsyncEnumerable source
+ ) : IAsyncBuffer
{
private readonly SemaphoreSlim _lock = new(initialCount: 1);
- private IAsyncEnumerable? _source;
+ private IAsyncEnumerable? _source = source;
private IAsyncEnumerator? _enumerator;
private bool _initialized;
@@ -33,11 +35,6 @@ private sealed class SharedBuffer : IAsyncBuffer
private bool _disposed;
- public SharedBuffer(IAsyncEnumerable source)
- {
- _source = source;
- }
-
public int Count => 0;
public async ValueTask Reset(CancellationToken cancellationToken = default)
diff --git a/Source/SuperLinq/AssertCount.cs b/Source/SuperLinq/AssertCount.cs
index d00b1702..db262b9d 100644
--- a/Source/SuperLinq/AssertCount.cs
+++ b/Source/SuperLinq/AssertCount.cs
@@ -57,31 +57,25 @@ static IEnumerable Core(IEnumerable source, int count)
}
}
- private sealed class AssertCountCollectionIterator : CollectionIterator
+ private sealed class AssertCountCollectionIterator(
+ IEnumerable source,
+ int count
+ ) : CollectionIterator
{
- private readonly IEnumerable _source;
- private readonly int _count;
-
- public AssertCountCollectionIterator(IEnumerable source, int count)
- {
- _source = source;
- _count = count;
- }
-
public override int Count
{
get
{
- ArgumentOutOfRangeException.ThrowIfNotEqual(_source.GetCollectionCount(), _count, "source.Count()");
- return _count;
+ ArgumentOutOfRangeException.ThrowIfNotEqual(source.GetCollectionCount(), count, "source.Count()");
+ return count;
}
}
protected override IEnumerable GetEnumerable()
{
- ArgumentOutOfRangeException.ThrowIfNotEqual(_source.GetCollectionCount(), _count, "source.Count()");
+ ArgumentOutOfRangeException.ThrowIfNotEqual(source.GetCollectionCount(), count, "source.Count()");
- foreach (var item in _source)
+ foreach (var item in source)
yield return item;
}
@@ -91,27 +85,21 @@ public override void CopyTo(T[] array, int arrayIndex)
ArgumentOutOfRangeException.ThrowIfNegative(arrayIndex);
ArgumentOutOfRangeException.ThrowIfGreaterThan(arrayIndex, array.Length - Count);
- _ = _source.CopyTo(array, arrayIndex);
+ _ = source.CopyTo(array, arrayIndex);
}
}
- private sealed class AssertCountListIterator : ListIterator
+ private sealed class AssertCountListIterator(
+ IList source,
+ int count
+ ) : ListIterator
{
- private readonly IList _source;
- private readonly int _count;
-
- public AssertCountListIterator(IList source, int count)
- {
- _source = source;
- _count = count;
- }
-
public override int Count
{
get
{
- ArgumentOutOfRangeException.ThrowIfNotEqual(_source.Count, _count, "source.Count()");
- return _count;
+ ArgumentOutOfRangeException.ThrowIfNotEqual(source.Count, count, "source.Count()");
+ return count;
}
}
@@ -120,7 +108,7 @@ protected override IEnumerable GetEnumerable()
var cnt = (uint)Count;
for (var i = 0; i < cnt; i++)
{
- yield return _source[i];
+ yield return source[i];
}
}
@@ -130,7 +118,7 @@ public override void CopyTo(T[] array, int arrayIndex)
ArgumentOutOfRangeException.ThrowIfNegative(arrayIndex);
ArgumentOutOfRangeException.ThrowIfGreaterThan(arrayIndex, array.Length - Count);
- _source.CopyTo(array, arrayIndex);
+ source.CopyTo(array, arrayIndex);
}
protected override T ElementAt(int index)
@@ -138,7 +126,7 @@ protected override T ElementAt(int index)
ArgumentOutOfRangeException.ThrowIfNegative(index);
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(index, Count);
- return _source[index];
+ return source[index];
}
}
}
diff --git a/Source/SuperLinq/Batch.cs b/Source/SuperLinq/Batch.cs
index 818a82e0..15be4e54 100644
--- a/Source/SuperLinq/Batch.cs
+++ b/Source/SuperLinq/Batch.cs
@@ -86,28 +86,22 @@ static IEnumerable> Core(IEnumerable source, int size)
}
}
- private sealed class BatchIterator : ListIterator>
+ private sealed class BatchIterator(
+ IList source,
+ int size
+ ) : ListIterator>
{
- private readonly IList _source;
- private readonly int _size;
-
- public BatchIterator(IList source, int size)
- {
- _source = source;
- _size = size;
- }
-
- public override int Count => _source.Count == 0 ? 0 : ((_source.Count - 1) / _size) + 1;
+ public override int Count => source.Count == 0 ? 0 : ((source.Count - 1) / size) + 1;
protected override IEnumerable> GetEnumerable()
{
var sourceIndex = 0;
- var count = (uint)_source.Count;
- while (sourceIndex + _size - 1 < count)
+ var count = (uint)source.Count;
+ while (sourceIndex + size - 1 < count)
{
- var window = new T[_size];
- for (var i = 0; i < _size && sourceIndex < count; sourceIndex++, i++)
- window[i] = _source[sourceIndex];
+ var window = new T[size];
+ for (var i = 0; i < size && sourceIndex < count; sourceIndex++, i++)
+ window[i] = source[sourceIndex];
yield return window;
}
@@ -116,7 +110,7 @@ protected override IEnumerable> GetEnumerable()
{
var window = new T[count - sourceIndex];
for (var j = 0; sourceIndex < count; sourceIndex++, j++)
- window[j] = _source[sourceIndex];
+ window[j] = source[sourceIndex];
yield return window;
}
@@ -127,11 +121,11 @@ protected override IList ElementAt(int index)
ArgumentOutOfRangeException.ThrowIfNegative(index);
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(index, Count);
- var start = index * _size;
- var max = (uint)Math.Min(_source.Count, start + _size);
- var arr = new T[Math.Min(_size, max - start)];
- for (int i = 0, j = start; i < _size && j < max; i++, j++)
- arr[i] = _source[j];
+ var start = index * size;
+ var max = (uint)Math.Min(source.Count, start + size);
+ var arr = new T[Math.Min(size, max - start)];
+ for (int i = 0, j = start; i < size && j < max; i++, j++)
+ arr[i] = source[j];
return arr;
}
diff --git a/Source/SuperLinq/CountDown.cs b/Source/SuperLinq/CountDown.cs
index 4d62e319..b01b3c2d 100644
--- a/Source/SuperLinq/CountDown.cs
+++ b/Source/SuperLinq/CountDown.cs
@@ -19,7 +19,7 @@ public static partial class SuperEnumerable
///
/// A sequence of tuples containing the element and it's count from the end of the sequence, or .
- ///
+ ///
///
/// is .
///
@@ -110,60 +110,46 @@ static IEnumerable Core(IEnumerable source, int count, Func : CollectionIterator
+ private sealed class CountDownCollectionIterator(
+ IEnumerable source,
+ int count,
+ Func resultSelector
+ ) : CollectionIterator
{
- private readonly IEnumerable _source;
- private readonly int _count;
- private readonly Func _resultSelector;
-
- public CountDownCollectionIterator(IEnumerable source, int count, Func resultSelector)
- {
- _source = source;
- _count = count;
- _resultSelector = resultSelector;
- }
-
- public override int Count => _source.GetCollectionCount();
+ public override int Count => source.GetCollectionCount();
protected override IEnumerable GetEnumerable()
{
var i = Count;
- foreach (var item in _source)
- yield return _resultSelector(item, i-- <= _count ? i : null);
+ foreach (var item in source)
+ yield return resultSelector(item, i-- <= count ? i : null);
}
}
- private sealed class CountDownListIterator : ListIterator
+ private sealed class CountDownListIterator(
+ IList source,
+ int count,
+ Func resultSelector
+ ) : ListIterator
{
- private readonly IList _source;
- private readonly int _count;
- private readonly Func _resultSelector;
-
- public CountDownListIterator(IList source, int count, Func resultSelector)
- {
- _source = source;
- _count = count;
- _resultSelector = resultSelector;
- }
-
- public override int Count => _source.Count;
+ public override int Count => source.Count;
protected override IEnumerable GetEnumerable()
{
- var cnt = (uint)_source.Count - _count;
+ var cnt = (uint)source.Count - count;
var i = 0;
for (; i < cnt; i++)
{
- yield return _resultSelector(
- _source[i],
+ yield return resultSelector(
+ source[i],
null);
}
- cnt = (uint)_source.Count;
+ cnt = (uint)source.Count;
for (; i < cnt; i++)
{
- yield return _resultSelector(
- _source[i],
+ yield return resultSelector(
+ source[i],
(int)cnt - i - 1);
}
}
@@ -173,9 +159,9 @@ protected override TResult ElementAt(int index)
ArgumentOutOfRangeException.ThrowIfNegative(index);
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(index, Count);
- return _resultSelector(
- _source[index],
- _source.Count - index < _count ? _source.Count - index - 1 : null);
+ return resultSelector(
+ source[index],
+ source.Count - index < count ? source.Count - index - 1 : null);
}
}
}
diff --git a/Source/SuperLinq/Exclude.cs b/Source/SuperLinq/Exclude.cs
index ec1549f0..065f6506 100644
--- a/Source/SuperLinq/Exclude.cs
+++ b/Source/SuperLinq/Exclude.cs
@@ -46,54 +46,40 @@ public static IEnumerable Exclude(this IEnumerable sequence, int startI
};
}
- private sealed class ExcludeCollectionIterator : CollectionIterator
+ private sealed class ExcludeCollectionIterator(
+ ICollection source,
+ int startIndex,
+ int count
+ ) : CollectionIterator
{
- private readonly ICollection _source;
- private readonly int _startIndex;
- private readonly int _count;
-
- public ExcludeCollectionIterator(ICollection source, int startIndex, int count)
- {
- _source = source;
- _startIndex = startIndex;
- _count = count;
- }
-
public override int Count =>
- _source.Count < _startIndex ? _source.Count :
- _source.Count < _startIndex + _count ? _startIndex :
- _source.Count - _count;
+ source.Count < startIndex ? source.Count :
+ source.Count < startIndex + count ? startIndex :
+ source.Count - count;
protected override IEnumerable GetEnumerable() =>
- ExcludeCore(_source, _startIndex, _count);
+ ExcludeCore(source, startIndex, count);
}
- private sealed class ExcludeListIterator : ListIterator
+ private sealed class ExcludeListIterator(
+ IList source,
+ int startIndex,
+ int count
+ ) : ListIterator
{
- private readonly IList _source;
- private readonly int _startIndex;
- private readonly int _count;
-
- public ExcludeListIterator(IList source, int startIndex, int count)
- {
- _source = source;
- _startIndex = startIndex;
- _count = count;
- }
-
public override int Count =>
- _source.Count < _startIndex ? _source.Count :
- _source.Count < _startIndex + _count ? _startIndex :
- _source.Count - _count;
+ source.Count < startIndex ? source.Count :
+ source.Count < startIndex + count ? startIndex :
+ source.Count - count;
protected override IEnumerable GetEnumerable()
{
- var cnt = (uint)_source.Count;
- for (var i = 0; i < cnt && i < _startIndex; i++)
- yield return _source[i];
+ var cnt = (uint)source.Count;
+ for (var i = 0; i < cnt && i < startIndex; i++)
+ yield return source[i];
- for (var i = _startIndex + _count; i < cnt; i++)
- yield return _source[i];
+ for (var i = startIndex + count; i < cnt; i++)
+ yield return source[i];
}
protected override T ElementAt(int index)
@@ -101,9 +87,9 @@ protected override T ElementAt(int index)
ArgumentOutOfRangeException.ThrowIfNegative(index);
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(index, Count);
- return index < _startIndex
- ? _source[index]
- : _source[index + _count];
+ return index < startIndex
+ ? source[index]
+ : source[index + count];
}
}
diff --git a/Source/SuperLinq/FallbackIfEmpty.cs b/Source/SuperLinq/FallbackIfEmpty.cs
index 7dcc2ea1..36406933 100644
--- a/Source/SuperLinq/FallbackIfEmpty.cs
+++ b/Source/SuperLinq/FallbackIfEmpty.cs
@@ -92,27 +92,21 @@ static IEnumerable Core(IEnumerable source, IEnumerable fallback)
}
}
- private sealed class FallbackIfEmptyCollectionIterator : CollectionIterator
+ private sealed class FallbackIfEmptyCollectionIterator(
+ IEnumerable source,
+ IEnumerable fallback
+ ) : CollectionIterator
{
- private readonly IEnumerable _source;
- private readonly IEnumerable _fallback;
-
- public FallbackIfEmptyCollectionIterator(IEnumerable source, IEnumerable fallback)
- {
- _source = source;
- _fallback = fallback;
- }
-
public override int Count =>
- _source.GetCollectionCount() == 0
- ? _fallback.Count()
- : _source.GetCollectionCount();
+ source.GetCollectionCount() == 0
+ ? fallback.Count()
+ : source.GetCollectionCount();
protected override IEnumerable GetEnumerable()
{
- return _source.GetCollectionCount() == 0
- ? _fallback
- : _source;
+ return source.GetCollectionCount() == 0
+ ? fallback
+ : source;
}
}
}
diff --git a/Source/SuperLinq/FillBackward.cs b/Source/SuperLinq/FillBackward.cs
index 9c44ef9b..3cd6bf31 100644
--- a/Source/SuperLinq/FillBackward.cs
+++ b/Source/SuperLinq/FillBackward.cs
@@ -138,24 +138,17 @@ private static IEnumerable FillBackwardCore(IEnumerable source, Func : CollectionIterator
+ private sealed class FillBackwardCollection(
+ ICollection source,
+ Func predicate,
+ Func? fillSelector
+ ) : CollectionIterator
{
- private readonly ICollection _source;
- private readonly Func _predicate;
- private readonly Func? _fillSelector;
-
- public FillBackwardCollection(ICollection source, Func predicate, Func? fillSelector)
- {
- _source = source;
- _predicate = predicate;
- _fillSelector = fillSelector;
- }
-
- public override int Count => _source.Count;
+ public override int Count => source.Count;
[ExcludeFromCodeCoverage]
protected override IEnumerable GetEnumerable() =>
- FillBackwardCore(_source, _predicate, _fillSelector);
+ FillBackwardCore(source, predicate, fillSelector);
public override void CopyTo(T[] array, int arrayIndex)
{
@@ -163,10 +156,10 @@ public override void CopyTo(T[] array, int arrayIndex)
ArgumentOutOfRangeException.ThrowIfNegative(arrayIndex);
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(arrayIndex, Count);
- _source.CopyTo(array, arrayIndex);
+ source.CopyTo(array, arrayIndex);
- var i = arrayIndex + _source.Count - 1;
- for (; i >= arrayIndex && _predicate(array[i]); i--)
+ var i = arrayIndex + source.Count - 1;
+ for (; i >= arrayIndex && predicate(array[i]); i--)
;
if (i < arrayIndex)
@@ -175,10 +168,10 @@ public override void CopyTo(T[] array, int arrayIndex)
var last = array[i--];
for (; i >= arrayIndex; i--)
{
- if (_predicate(array[i]))
+ if (predicate(array[i]))
{
- array[i] = _fillSelector != null
- ? _fillSelector(array[i], last)
+ array[i] = fillSelector != null
+ ? fillSelector(array[i], last)
: last;
}
else
diff --git a/Source/SuperLinq/FillForward.cs b/Source/SuperLinq/FillForward.cs
index ee7c9e04..56250661 100644
--- a/Source/SuperLinq/FillForward.cs
+++ b/Source/SuperLinq/FillForward.cs
@@ -127,24 +127,17 @@ private static IEnumerable FillForwardCore(IEnumerable source, Func : CollectionIterator
+ private sealed class FillForwardCollection(
+ ICollection source,
+ Func predicate,
+ Func? fillSelector
+ ) : CollectionIterator
{
- private readonly ICollection _source;
- private readonly Func _predicate;
- private readonly Func? _fillSelector;
-
- public FillForwardCollection(ICollection source, Func predicate, Func? fillSelector)
- {
- _source = source;
- _predicate = predicate;
- _fillSelector = fillSelector;
- }
-
- public override int Count => _source.Count;
+ public override int Count => source.Count;
[ExcludeFromCodeCoverage]
protected override IEnumerable GetEnumerable() =>
- FillForwardCore(_source, _predicate, _fillSelector);
+ FillForwardCore(source, predicate, fillSelector);
public override void CopyTo(T[] array, int arrayIndex)
{
@@ -152,11 +145,11 @@ public override void CopyTo(T[] array, int arrayIndex)
ArgumentOutOfRangeException.ThrowIfNegative(arrayIndex);
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(arrayIndex, Count);
- _source.CopyTo(array, arrayIndex);
+ source.CopyTo(array, arrayIndex);
var i = arrayIndex;
- var max = arrayIndex + _source.Count;
- for (; i < max && _predicate(array[i]); i++)
+ var max = arrayIndex + source.Count;
+ for (; i < max && predicate(array[i]); i++)
;
if (i >= max)
@@ -165,10 +158,10 @@ public override void CopyTo(T[] array, int arrayIndex)
var last = array[i++];
for (; i < max; i++)
{
- if (_predicate(array[i]))
+ if (predicate(array[i]))
{
- array[i] = _fillSelector != null
- ? _fillSelector(array[i], last)
+ array[i] = fillSelector != null
+ ? fillSelector(array[i], last)
: last;
}
else
diff --git a/Source/SuperLinq/GroupAdjacent.cs b/Source/SuperLinq/GroupAdjacent.cs
index fa3e165f..0921c969 100644
--- a/Source/SuperLinq/GroupAdjacent.cs
+++ b/Source/SuperLinq/GroupAdjacent.cs
@@ -328,17 +328,14 @@ private static Grouping CreateGroupAdjacentGrouping : IGrouping
+ private sealed class Grouping(
+ TKey key,
+ IEnumerable members
+ ) : IGrouping
{
- private readonly IEnumerable _members;
+ private readonly IEnumerable _members = members;
- public Grouping(TKey key, IEnumerable members)
- {
- Key = key;
- _members = members;
- }
-
- public TKey Key { get; }
+ public TKey Key { get; } = key;
public IEnumerator GetEnumerator() => _members.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
diff --git a/Source/SuperLinq/Index.cs b/Source/SuperLinq/Index.cs
index 7cd9591b..283330ff 100644
--- a/Source/SuperLinq/Index.cs
+++ b/Source/SuperLinq/Index.cs
@@ -67,46 +67,34 @@ public static partial class SuperEnumerable
}
}
- private sealed class IndexCollectionIterator : CollectionIterator<(int index, T item)>
+ private sealed class IndexCollectionIterator(
+ IEnumerable source,
+ int startIndex
+ ) : CollectionIterator<(int index, T item)>
{
- private readonly IEnumerable _source;
- private readonly int _startIndex;
-
- public IndexCollectionIterator(IEnumerable source, int startIndex)
- {
- _source = source;
- _startIndex = startIndex;
- }
-
- public override int Count => _source.GetCollectionCount();
+ public override int Count => source.GetCollectionCount();
protected override IEnumerable<(int index, T item)> GetEnumerable()
{
- var index = _startIndex;
- foreach (var item in _source)
+ var index = startIndex;
+ foreach (var item in source)
yield return (index++, item);
}
}
- private sealed class IndexListIterator : ListIterator<(int index, T item)>
+ private sealed class IndexListIterator(
+ IList source,
+ int startIndex
+ ) : ListIterator<(int index, T item)>
{
- private readonly IList _source;
- private readonly int _startIndex;
-
- public IndexListIterator(IList source, int startIndex)
- {
- _source = source;
- _startIndex = startIndex;
- }
-
- public override int Count => _source.Count;
+ public override int Count => source.Count;
protected override IEnumerable<(int index, T item)> GetEnumerable()
{
var cnt = (uint)Count;
for (var i = 0; i < cnt; i++)
{
- yield return (_startIndex + i, _source[i]);
+ yield return (startIndex + i, source[i]);
}
}
@@ -115,7 +103,7 @@ protected override (int index, T item) ElementAt(int index)
ArgumentOutOfRangeException.ThrowIfNegative(index);
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(index, Count);
- return (_startIndex + index, _source[index]);
+ return (startIndex + index, source[index]);
}
}
}
diff --git a/Source/SuperLinq/Insert.cs b/Source/SuperLinq/Insert.cs
index 26d3e09c..a3bf7a22 100644
--- a/Source/SuperLinq/Insert.cs
+++ b/Source/SuperLinq/Insert.cs
@@ -146,40 +146,33 @@ private static IEnumerable InsertCore(IEnumerable first, IEnumerable
yield return iter.Current;
}
- private sealed class InsertCollectionIterator : CollectionIterator
+ private sealed class InsertCollectionIterator(
+ IEnumerable first,
+ IEnumerable second,
+ Index index
+ ) : CollectionIterator
{
- private readonly IEnumerable _first;
- private readonly IEnumerable _second;
- private readonly Index _index;
-
- public InsertCollectionIterator(IEnumerable first, IEnumerable second, Index index)
- {
- _first = first;
- _second = second;
- _index = index;
- }
-
public override int Count
{
get
{
- var fCount = _first.GetCollectionCount();
- var idx = _index.GetOffset(fCount);
+ var fCount = first.GetCollectionCount();
+ var idx = index.GetOffset(fCount);
ArgumentOutOfRangeException.ThrowIfNegative(idx);
ArgumentOutOfRangeException.ThrowIfGreaterThan(idx, fCount);
- return fCount + _second.GetCollectionCount();
+ return fCount + second.GetCollectionCount();
}
}
protected override IEnumerable GetEnumerable()
{
- var fCount = _first.GetCollectionCount();
- var idx = _index.GetOffset(fCount);
+ var fCount = first.GetCollectionCount();
+ var idx = index.GetOffset(fCount);
ArgumentOutOfRangeException.ThrowIfNegative(idx);
ArgumentOutOfRangeException.ThrowIfGreaterThan(idx, fCount);
- return InsertCore(_first, _second, idx);
+ return InsertCore(first, second, idx);
}
public override void CopyTo(T[] array, int arrayIndex)
@@ -188,29 +181,26 @@ public override void CopyTo(T[] array, int arrayIndex)
ArgumentOutOfRangeException.ThrowIfNegative(arrayIndex);
ArgumentOutOfRangeException.ThrowIfGreaterThan(arrayIndex, array.Length - Count);
- _ = _first.CopyTo(array, arrayIndex);
+ _ = first.CopyTo(array, arrayIndex);
var span = array.AsSpan()[arrayIndex..];
- var cnt = _first.GetCollectionCount();
- var idx = _index.GetOffset(cnt);
- span[idx..cnt].CopyTo(span[(idx + _second.GetCollectionCount())..]);
+ var cnt = first.GetCollectionCount();
+ var idx = index.GetOffset(cnt);
+ span[idx..cnt].CopyTo(span[(idx + second.GetCollectionCount())..]);
- _ = _second.CopyTo(array, arrayIndex + idx);
+ _ = second.CopyTo(array, arrayIndex + idx);
}
}
- private sealed class InsertListIterator : ListIterator
+ private sealed class InsertListIterator(
+ IList first,
+ IList second,
+ Index index
+ ) : ListIterator
{
- private readonly IList _first;
- private readonly IList _second;
- private readonly Index _index;
-
- public InsertListIterator(IList first, IList second, Index index)
- {
- _first = first;
- _second = second;
- _index = index;
- }
+ private readonly IList _first = first;
+ private readonly IList _second = second;
+ private readonly Index _index = index;
public override int Count
{
diff --git a/Source/SuperLinq/Interleave.cs b/Source/SuperLinq/Interleave.cs
index 43101c5d..b60d9d47 100644
--- a/Source/SuperLinq/Interleave.cs
+++ b/Source/SuperLinq/Interleave.cs
@@ -87,19 +87,14 @@ private static IEnumerable InterleaveCore(IEnumerable> sour
}
}
- private sealed class InterleaveIterator : CollectionIterator
+ private sealed class InterleaveIterator(
+ IEnumerable> sources
+ ) : CollectionIterator
{
- private readonly IEnumerable> _sources;
-
- public InterleaveIterator(IEnumerable> sources)
- {
- _sources = sources;
- }
-
- public override int Count => _sources.Sum(static s => s.Count);
+ public override int Count => sources.Sum(static s => s.Count);
[ExcludeFromCodeCoverage]
protected override IEnumerable