Skip to content
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

Discard unused parameters #864

Merged
merged 1 commit into from
Nov 4, 2022
Merged
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
2 changes: 1 addition & 1 deletion MoreLinq.Test/AggregateRightTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void AggregateRight(SourceKind sourceKind)
[TestCase(true)]
public void AggregateRightSeedWithEmptySequence(object defaultValue)
{
Assert.That(new int[0].AggregateRight(defaultValue, (a, b) => b), Is.EqualTo(defaultValue));
Assert.That(new int[0].AggregateRight(defaultValue, (_, b) => b), Is.EqualTo(defaultValue));
}

[Test]
Expand Down
8 changes: 4 additions & 4 deletions MoreLinq.Test/BreakingAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ static class BreakingAction
() => throw new NotImplementedException();

internal static Action<T> Of<T>() =>
t => throw new NotImplementedException();
_ => throw new NotImplementedException();

internal static Action<T1, T2> Of<T1, T2>() =>
(t1, t2) => throw new NotImplementedException();
(_, _) => throw new NotImplementedException();

internal static Action<T1, T2, T3> Of<T1, T2, T3>() =>
(t1, t2, t3) => throw new NotImplementedException();
(_, _, _) => throw new NotImplementedException();

internal static Action<T1, T2, T3, T4> Of<T1, T2, T3, T4>() =>
(t1, t2, t3, t4) => throw new NotImplementedException();
(_, _, _, _) => throw new NotImplementedException();
}
}
8 changes: 4 additions & 4 deletions MoreLinq.Test/BreakingFunc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ internal static Func<TResult> Of<TResult>() =>
() => throw new NotImplementedException();

internal static Func<T, TResult> Of<T, TResult>() =>
t => throw new NotImplementedException();
_ => throw new NotImplementedException();

internal static Func<T1, T2, TResult> Of<T1, T2, TResult>() =>
(t1, t2) => throw new NotImplementedException();
(_, _) => throw new NotImplementedException();

internal static Func<T1, T2, T3, TResult> Of<T1, T2, T3, TResult>() =>
(t1, t2, t3) => throw new NotImplementedException();
(_, _, _) => throw new NotImplementedException();

internal static Func<T1, T2, T3, T4, TResult> Of<T1, T2, T3, T4, TResult>() =>
(t1, t2, t3, t4) => throw new NotImplementedException();
(_, _, _, _) => throw new NotImplementedException();
}
}
2 changes: 1 addition & 1 deletion MoreLinq.Test/ConsumeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class ConsumeTest
public void ConsumeReallyConsumes()
{
var counter = 0;
var sequence = Enumerable.Range(0, 10).Pipe(x => counter++);
var sequence = Enumerable.Range(0, 10).Pipe(_ => counter++);
sequence.Consume();
Assert.AreEqual(10, counter);
}
Expand Down
4 changes: 2 additions & 2 deletions MoreLinq.Test/GroupAdjacentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void GroupAdjacentSourceSequenceResultSelector()
new { Month = 1, Value = 781 },
};

var groupings = source.GroupAdjacent(e => e.Month, (key, group) => group.Sum(v => v.Value));
var groupings = source.GroupAdjacent(e => e.Month, (_, group) => group.Sum(v => v.Value));

using var reader = groupings.Read();
AssertResult(reader, 123 + 456 + 789);
Expand Down Expand Up @@ -188,7 +188,7 @@ public void GroupAdjacentSourceSequenceResultSelectorComparer()
new { Month = "JAN", Value = 781 },
};

var groupings = source.GroupAdjacent(e => e.Month, (key, group) => group.Sum(v => v.Value), StringComparer.OrdinalIgnoreCase);
var groupings = source.GroupAdjacent(e => e.Month, (_, group) => group.Sum(v => v.Value), StringComparer.OrdinalIgnoreCase);

using var reader = groupings.Read();
AssertResult(reader, 123 + 456 + 789);
Expand Down
8 changes: 4 additions & 4 deletions MoreLinq.Test/LagTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void TestLagIsLazy()
public void TestLagNegativeOffsetException()
{
AssertThrowsArgument.OutOfRangeException("offset",() =>
Enumerable.Repeat(1, 10).Lag(-10, (val, lagVal) => val));
Enumerable.Repeat(1, 10).Lag(-10, (val, _) => val));
}

/// <summary>
Expand All @@ -67,7 +67,7 @@ public void TestLagExplicitDefaultValue()
const int lagBy = 10;
const int lagDefault = -1;
var sequence = Enumerable.Range(1, count);
var result = sequence.Lag(lagBy, lagDefault, (val, lagVal) => lagVal);
var result = sequence.Lag(lagBy, lagDefault, (_, lagVal) => lagVal);

Assert.AreEqual(count, result.Count());
Assert.That(result.Take(lagBy), Is.EqualTo(Enumerable.Repeat(lagDefault, lagBy)));
Expand All @@ -82,7 +82,7 @@ public void TestLagImplicitDefaultValue()
const int count = 100;
const int lagBy = 10;
var sequence = Enumerable.Range(1, count);
var result = sequence.Lag(lagBy, (val, lagVal) => lagVal);
var result = sequence.Lag(lagBy, (_, lagVal) => lagVal);

Assert.AreEqual(count, result.Count());
Assert.That(result.Take(lagBy), Is.EqualTo(Enumerable.Repeat(default(int), lagBy)));
Expand All @@ -97,7 +97,7 @@ public void TestLagOffsetGreaterThanSequenceLength()
{
const int count = 100;
var sequence = Enumerable.Range(1, count);
var result = sequence.Lag(count + 1, (a, b) => a);
var result = sequence.Lag(count + 1, (a, _) => a);

Assert.AreEqual(count, result.Count());
Assert.That(result, Is.EqualTo(sequence));
Expand Down
4 changes: 2 additions & 2 deletions MoreLinq.Test/LeadTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void TestLeadExplicitDefaultValue()
const int leadBy = 10;
const int leadDefault = -1;
var sequence = Enumerable.Range(1, count);
var result = sequence.Lead(leadBy, leadDefault, (val, leadVal) => leadVal);
var result = sequence.Lead(leadBy, leadDefault, (_, leadVal) => leadVal);

Assert.AreEqual(count, result.Count());
Assert.That(result.Skip(count - leadBy), Is.EqualTo(Enumerable.Repeat(leadDefault, leadBy)));
Expand All @@ -82,7 +82,7 @@ public void TestLeadImplicitDefaultValue()
const int count = 100;
const int leadBy = 10;
var sequence = Enumerable.Range(1, count);
var result = sequence.Lead(leadBy, (val, leadVal) => leadVal);
var result = sequence.Lead(leadBy, (_, leadVal) => leadVal);

Assert.AreEqual(count, result.Count());
Assert.That(result.Skip(count - leadBy), Is.EqualTo(Enumerable.Repeat(default(int), leadBy)));
Expand Down
12 changes: 6 additions & 6 deletions MoreLinq.Test/ScanByTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void ScanBy()
[Test]
public void ScanByWithSecondOccurenceImmediatelyAfterFirst()
{
var result = "jaffer".ScanBy(c => c, k => -1, (i, k, e) => i + 1);
var result = "jaffer".ScanBy(c => c, _ => -1, (i, _, _) => i + 1);

result.AssertSequenceEqual(
KeyValuePair.Create('j', 0),
Expand All @@ -83,8 +83,8 @@ public void ScanByWithEqualityComparer()
{
var source = new[] { "a", "B", "c", "A", "b", "A" };
var result = source.ScanBy(c => c,
k => -1,
(i, k, e) => i + 1,
_ => -1,
(i, _, _) => i + 1,
StringComparer.OrdinalIgnoreCase);

result.AssertSequenceEqual(
Expand All @@ -100,7 +100,7 @@ public void ScanByWithEqualityComparer()
public void ScanByWithSomeNullKeys()
{
var source = new[] { "foo", null, "bar", "baz", null, null, "baz", "bar", null, "foo" };
var result = source.ScanBy(c => c, k => -1, (i, k, e) => i + 1);
var result = source.ScanBy(c => c, _ => -1, (i, _, _) => i + 1);

result.AssertSequenceEqual(
KeyValuePair.Create("foo" , 0),
Expand All @@ -120,7 +120,7 @@ public void ScanByWithNullSeed()
{
var nil = (object)null;
var source = new[] { "foo", null, "bar", null, "baz" };
var result = source.ScanBy(c => c, k => nil, (i, k, e) => nil);
var result = source.ScanBy(c => c, _ => nil, (_, _, _) => nil);

result.AssertSequenceEqual(
KeyValuePair.Create("foo" , nil),
Expand All @@ -142,7 +142,7 @@ public void ScanByDoesNotIterateUnnecessaryElements()
() => "angelo",
() => "carlos");

var result = source.ScanBy(c => c.First(), k => -1, (i, k, e) => i + 1);
var result = source.ScanBy(c => c.First(), _ => -1, (i, _, _) => i + 1);

result.Take(5).AssertSequenceEqual(
KeyValuePair.Create('a', 0),
Expand Down
2 changes: 1 addition & 1 deletion MoreLinq.Test/ScanRightTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void ScanRightIsLazy()
[TestCase(true)]
public void ScanRightSeedWithEmptySequence(object defaultValue)
{
Assert.That(new int[0].ScanRight(defaultValue, (a, b) => b), Is.EqualTo(new[] { defaultValue }));
Assert.That(new int[0].ScanRight(defaultValue, (_, b) => b), Is.EqualTo(new[] { defaultValue }));
}

[Test]
Expand Down
16 changes: 8 additions & 8 deletions MoreLinq.Test/SegmentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void TestIdentitySegment()
{
const int count = 5;
var sequence = Enumerable.Range(1, count);
var result = sequence.Segment(x => false);
var result = sequence.Segment(_ => false);

Assert.That(result.Single(), Is.EqualTo(sequence));
}
Expand All @@ -58,7 +58,7 @@ public void TestIdentitySegment()
public void TestEmptySequence()
{
var sequence = Enumerable.Repeat(-1, 0);
var result = sequence.Segment(x => true);
var result = sequence.Segment(_ => true);
Assert.That(result, Is.Empty);
}

Expand All @@ -70,7 +70,7 @@ public void TestSegmentIsIdempotent()
{
const int value = -1;
var sequence = Enumerable.Repeat(value, 10);
var result = sequence.Segment(x => true);
var result = sequence.Segment(_ => true);

foreach (var segment in result)
{
Expand All @@ -90,9 +90,9 @@ public void TestSegmentIsIdempotent()
public void TestFirstSegmentNeverEmpty()
{
var sequence = Enumerable.Repeat(-1, 10);
var resultA = sequence.Segment(x => true);
var resultB = sequence.Segment((x, index) => true);
var resultC = sequence.Segment((x, prevX, index) => true);
var resultA = sequence.Segment(_ => true);
var resultB = sequence.Segment((_, _) => true);
var resultC = sequence.Segment((_, _, _) => true);

Assert.IsTrue(resultA.First().Any());
Assert.IsTrue(resultB.First().Any());
Expand Down Expand Up @@ -125,7 +125,7 @@ public void VerifyCanSegmentByIndex()
const int segmentSize = 2;

var sequence = Enumerable.Repeat(1, count);
var result = sequence.Segment((x, i) => i % segmentSize == 0);
var result = sequence.Segment((_, i) => i % segmentSize == 0);

Assert.AreEqual(count / segmentSize, result.Count());
foreach (var segment in result)
Expand All @@ -143,7 +143,7 @@ public void VerifyCanSegmentByPrevious()
const int repCount = 5;
var sequence = Enumerable.Range(1, 3)
.SelectMany(x => Enumerable.Repeat(x, repCount));
var result = sequence.Segment((curr, prev, i) => curr != prev);
var result = sequence.Segment((curr, prev, _) => curr != prev);

Assert.AreEqual(sequence.Distinct().Count(), result.Count());
Assert.IsTrue(result.All(s => s.Count() == repCount));
Expand Down
4 changes: 2 additions & 2 deletions MoreLinq.Test/TraverseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public class TraverseTest
[Test]
public void TraverseDepthFirstFNullGenerator()
{
MoreEnumerable.TraverseDepthFirst(new object(), o => new BreakingSequence<object>());
MoreEnumerable.TraverseDepthFirst(new object(), _ => new BreakingSequence<object>());
}

[Test]
public void TraverseBreadthFirstIsStreaming()
{
MoreEnumerable.TraverseBreadthFirst(new object(), o => new BreakingSequence<object>());
MoreEnumerable.TraverseBreadthFirst(new object(), _ => new BreakingSequence<object>());
}

[Test]
Expand Down
2 changes: 1 addition & 1 deletion MoreLinq/Consume.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static partial class MoreEnumerable
public static void Consume<T>(this IEnumerable<T> source)
{
if (source == null) throw new ArgumentNullException(nameof(source));
foreach (var element in source)
foreach (var _ in source)
{
}
}
Expand Down
2 changes: 1 addition & 1 deletion MoreLinq/EquiZip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static IEnumerable<TResult> EquiZip<TFirst, TSecond, TResult>(
if (second == null) throw new ArgumentNullException(nameof(second));
if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector));

return EquiZipImpl<TFirst, TSecond, object, object, TResult>(first, second, null, null, (a, b, c, d) => resultSelector(a, b));
return EquiZipImpl<TFirst, TSecond, object, object, TResult>(first, second, null, null, (a, b, _, _) => resultSelector(a, b));
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion MoreLinq/IndexBy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static IEnumerable<KeyValuePair<int, TSource>>
this IEnumerable<TSource> source,
Func<TSource, TKey> keySelector,
IEqualityComparer<TKey>? comparer) =>
from e in source.ScanBy(keySelector, k => (Index: -1, Item: default(TSource)), (s, k, e) => (s.Index + 1, e), comparer)
from e in source.ScanBy(keySelector, _ => (Index: -1, Item: default(TSource)), (s, _, e) => (s.Index + 1, e), comparer)
select new KeyValuePair<int, TSource>(e.Value.Index, e.Value.Item);
}
}
2 changes: 1 addition & 1 deletion MoreLinq/NestedLoops.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static IEnumerable<Action> NestedLoops(this Action action, IEnumerable<int> loop
return _(); IEnumerable<Action> _()
{
var count = loopCounts.Assert(n => n >= 0,
n => new InvalidOperationException("Invalid loop count (must be greater than or equal to zero)."))
_ => new InvalidOperationException("Invalid loop count (must be greater than or equal to zero)."))
.DefaultIfEmpty()
.Aggregate((acc, x) => acc * x);

Expand Down
4 changes: 2 additions & 2 deletions MoreLinq/Partition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public static TResult Partition<TKey, TElement, TResult>(this IEnumerable<IGroup
{
if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector));
return PartitionImpl(source, 1, key, default!, default!, comparer,
(a, b, c, rest) => resultSelector(a, rest));
(a, _, _, rest) => resultSelector(a, rest));
}

/// <summary>
Expand Down Expand Up @@ -237,7 +237,7 @@ public static TResult Partition<TKey, TElement, TResult>(this IEnumerable<IGroup
{
if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector));
return PartitionImpl(source, 2, key1, key2, default!, comparer,
(a, b, c, rest) => resultSelector(a, b, rest));
(a, b, _, rest) => resultSelector(a, b, rest));
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion MoreLinq/Scan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static IEnumerable<TState> Scan<TSource, TState>(this IEnumerable<TSource
if (source == null) throw new ArgumentNullException(nameof(source));
if (transformation == null) throw new ArgumentNullException(nameof(transformation));

return ScanImpl(source, transformation, e => (true, seed));
return ScanImpl(source, transformation, _ => (true, seed));
}

static IEnumerable<TState> ScanImpl<TSource, TState>(IEnumerable<TSource> source,
Expand Down
4 changes: 2 additions & 2 deletions MoreLinq/Segment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static IEnumerable<IEnumerable<T>> Segment<T>(this IEnumerable<T> source,
{
if (newSegmentPredicate == null) throw new ArgumentNullException(nameof(newSegmentPredicate));

return Segment(source, (curr, prev, index) => newSegmentPredicate(curr));
return Segment(source, (curr, _, _) => newSegmentPredicate(curr));
}

/// <summary>
Expand All @@ -55,7 +55,7 @@ public static IEnumerable<IEnumerable<T>> Segment<T>(this IEnumerable<T> source,
{
if (newSegmentPredicate == null) throw new ArgumentNullException(nameof(newSegmentPredicate));

return Segment(source, (curr, prev, index) => newSegmentPredicate(curr, index));
return Segment(source, (curr, _, index) => newSegmentPredicate(curr, index));
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion MoreLinq/TakeEvery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static IEnumerable<TSource> TakeEvery<TSource>(this IEnumerable<TSource>
{
if (source == null) throw new ArgumentNullException(nameof(source));
if (step <= 0) throw new ArgumentOutOfRangeException(nameof(step));
return source.Where((e, i) => i % step == 0);
return source.Where((_, i) => i % step == 0);
}
}
}
4 changes: 2 additions & 2 deletions MoreLinq/ZipLongest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static IEnumerable<TResult> ZipLongest<TFirst, TSecond, TResult>(
if (second == null) throw new ArgumentNullException(nameof(second));
if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector));

return ZipImpl<TFirst, TSecond, object, object, TResult>(first, second, null, null, (a, b, c, d) => resultSelector(a, b), 1);
return ZipImpl<TFirst, TSecond, object, object, TResult>(first, second, null, null, (a, b, _, _) => resultSelector(a, b), 1);
}

/// <summary>
Expand Down Expand Up @@ -110,7 +110,7 @@ public static IEnumerable<TResult> ZipLongest<T1, T2, T3, TResult>(
if (third == null) throw new ArgumentNullException(nameof(third));
if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector));

return ZipImpl<T1, T2, T3, object, TResult>(first, second, third, null, (a, b, c, d) => resultSelector(a, b, c), 2);
return ZipImpl<T1, T2, T3, object, TResult>(first, second, third, null, (a, b, c, _) => resultSelector(a, b, c), 2);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion MoreLinq/ZipShortest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static IEnumerable<TResult> ZipShortest<TFirst, TSecond, TResult>(
if (second == null) throw new ArgumentNullException(nameof(second));
if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector));

return ZipImpl<TFirst, TSecond, object, object, TResult>(first, second, null, null, (a, b, c, d) => resultSelector(a, b));
return ZipImpl<TFirst, TSecond, object, object, TResult>(first, second, null, null, (a, b, _, _) => resultSelector(a, b));
}

/// <summary>
Expand Down