From ff17951fb13236706369f8c0b6bd78e2ed390f78 Mon Sep 17 00:00:00 2001 From: Stuart Turner Date: Fri, 12 Apr 2024 10:29:00 -0500 Subject: [PATCH 1/4] Style consistency improvements --- .editorconfig | 7 +- .../SuperLinq.Generator/ToDelimitedString.cs | 5 +- Source/SuperLinq.Async/AggregateRight.cs | 71 +++++++++++--- Source/SuperLinq.Async/AssertCount.cs | 1 + .../SuperLinq.Async/AsyncSuperEnumerable.cs | 8 +- Source/SuperLinq.Async/BindByIndex.cs | 40 ++++++-- Source/SuperLinq.Async/Catch.cs | 2 +- Source/SuperLinq.Async/Choose.cs | 17 +++- Source/SuperLinq.Async/CollectionEqual.cs | 4 +- Source/SuperLinq.Async/ConcurrentMerge.cs | 8 +- Source/SuperLinq.Async/Consume.cs | 4 +- Source/SuperLinq.Async/CopyTo.cs | 16 ++- Source/SuperLinq.Async/CountBy.cs | 27 +++++- Source/SuperLinq.Async/CountDown.cs | 14 ++- Source/SuperLinq.Async/CountMethods.cs | 29 +++++- Source/SuperLinq.Async/DensePartialSort.cs | 53 +++++++--- Source/SuperLinq.Async/DistinctBy.cs | 15 ++- .../SuperLinq.Async/DistinctUntilChanged.cs | 32 ++++-- Source/SuperLinq.Async/Do.cs | 40 ++++++-- Source/SuperLinq.Async/DoWhile.cs | 3 +- Source/SuperLinq.Async/Duplicates.cs | 10 +- Source/SuperLinq.Async/ElementAt.cs | 34 ++++--- Source/SuperLinq.Async/EndsWith.cs | 40 ++++++-- Source/SuperLinq.Async/EnumeratorList.cs | 1 + Source/SuperLinq.Async/ExceptBy.cs | 13 ++- Source/SuperLinq.Async/FallbackIfEmpty.cs | 14 ++- Source/SuperLinq.Async/FillBackward.cs | 31 +++++- Source/SuperLinq.Async/FillForward.cs | 33 +++++-- Source/SuperLinq.Async/FindIndex.cs | 40 ++++++-- Source/SuperLinq.Async/FindLastIndex.cs | 38 ++++++-- Source/SuperLinq.Async/From.cs | 31 ++++-- Source/SuperLinq.Async/Generate.cs | 8 +- Source/SuperLinq.Async/GetShortestPath.cs | 69 +++++++------ Source/SuperLinq.Async/GroupAdjacent.cs | 5 +- Source/SuperLinq.Async/HasDuplicates.cs | 16 +-- Source/SuperLinq.Async/Index.cs | 6 +- Source/SuperLinq.Async/IndexOf.cs | 23 ++++- Source/SuperLinq.Async/Insert.cs | 16 ++- Source/SuperLinq.Async/Interleave.cs | 9 +- Source/SuperLinq.Async/Join.HashJoin.cs | 1 + Source/SuperLinq.Async/Join.MergeJoin.cs | 7 +- Source/SuperLinq.Async/Lag.cs | 50 +++++++--- Source/SuperLinq.Async/LastIndexOf.cs | 31 +++++- Source/SuperLinq.Async/Lead.cs | 39 ++++++-- Source/SuperLinq.Async/MaxItems.cs | 36 ++++--- Source/SuperLinq.Async/Memoize.cs | 3 + Source/SuperLinq.Async/MinItems.cs | 31 ++++-- Source/SuperLinq.Async/OnErrorResumeNext.cs | 2 +- Source/SuperLinq.Async/OrderBy.cs | 36 +++++-- Source/SuperLinq.Async/PadStart.cs | 11 ++- Source/SuperLinq.Async/PartialSort.cs | 63 ++++++++---- Source/SuperLinq.Async/Publish.cs | 5 +- Source/SuperLinq.Async/Random.cs | 8 +- Source/SuperLinq.Async/Repeat.cs | 14 ++- Source/SuperLinq.Async/RunLengthEncode.cs | 8 +- Source/SuperLinq.Async/ScanRight.cs | 42 ++++++-- Source/SuperLinq.Async/Segment.cs | 30 ++++-- Source/SuperLinq.Async/Share.cs | 3 + Source/SuperLinq.Async/SkipUntil.cs | 8 +- Source/SuperLinq.Async/SortedMerge.cs | 61 ++++++++++-- Source/SuperLinq.Async/StartsWith.cs | 42 +++++--- Source/SuperLinq.Async/TagFirstLast.cs | 13 ++- Source/SuperLinq.Async/Take.cs | 33 ++++--- Source/SuperLinq.Async/TakeUntil.cs | 8 +- Source/SuperLinq.Async/Throw.cs | 2 +- Source/SuperLinq.Async/Traverse.cs | 8 +- Source/SuperLinq.Async/Using.cs | 2 +- Source/SuperLinq.Async/Where.cs | 10 +- Source/SuperLinq.Async/WhereLag.cs | 36 +++++-- Source/SuperLinq.Async/WhereLead.cs | 28 +++++- Source/SuperLinq.Async/Window.cs | 1 + Source/SuperLinq.Async/ZipMap.cs | 17 +++- Source/SuperLinq/AggregateRight.cs | 15 ++- Source/SuperLinq/AssertCount.cs | 5 +- Source/SuperLinq/BindByIndex.cs | 31 +++++- Source/SuperLinq/Catch.cs | 2 +- Source/SuperLinq/CollectionIterator.cs | 5 +- .../Collections/NullKeyDictionary.cs | 10 +- .../Collections/UpdatablePriorityQueue.cs | 97 +++++-------------- Source/SuperLinq/Consume.cs | 7 +- Source/SuperLinq/CopyTo.cs | 3 +- Source/SuperLinq/CountBy.cs | 34 +++++-- Source/SuperLinq/DensePartialSort.cs | 40 ++++---- Source/SuperLinq/DistinctUntilChanged.cs | 8 +- Source/SuperLinq/Do.cs | 16 ++- Source/SuperLinq/DoWhile.cs | 3 +- Source/SuperLinq/ElementAt.cs | 20 ++-- Source/SuperLinq/EndsWith.cs | 8 +- Source/SuperLinq/ExceptBy.cs | 10 +- .../Exceptions/ArgumentNullException.cs | 4 +- Source/SuperLinq/Exclude.cs | 7 +- Source/SuperLinq/FallbackIfEmpty.cs | 7 +- Source/SuperLinq/FillBackward.cs | 2 + Source/SuperLinq/FillForward.cs | 2 + Source/SuperLinq/FindIndex.cs | 13 +-- Source/SuperLinq/FindLastIndex.cs | 11 +-- Source/SuperLinq/FullGroupJoin.cs | 3 +- Source/SuperLinq/GetShortestPath.A-Star.cs | 3 +- Source/SuperLinq/GetShortestPath.Dijkstra.cs | 3 +- .../SuperLinq/GetShortestPathCost.A-Star.cs | 3 +- .../SuperLinq/GetShortestPathCost.Dijkstra.cs | 3 +- Source/SuperLinq/GetShortestPaths.cs | 3 +- Source/SuperLinq/GlobalSuppressions.cs | 19 +++- Source/SuperLinq/GroupAdjacent.cs | 4 +- Source/SuperLinq/Index.cs | 4 +- Source/SuperLinq/Insert.cs | 22 +++-- Source/SuperLinq/Interleave.cs | 4 +- Source/SuperLinq/Join.HashJoin.cs | 1 + Source/SuperLinq/Join.MergeJoin.cs | 25 ++--- .../SuperLinq/KeyValuePairEqualityComparer.cs | 12 +-- Source/SuperLinq/Lag.cs | 24 ++++- Source/SuperLinq/Lead.cs | 27 +++++- Source/SuperLinq/ListIterator.cs | 4 +- Source/SuperLinq/Lookup.cs | 22 ++++- Source/SuperLinq/MaxItems.cs | 38 +++++--- Source/SuperLinq/Memoize.cs | 32 +++++- Source/SuperLinq/MinItems.cs | 38 +++++--- Source/SuperLinq/OnErrorResumeNext.cs | 4 +- Source/SuperLinq/OrderBy.cs | 30 ++++-- Source/SuperLinq/OrderByDirection.cs | 3 +- Source/SuperLinq/PadStart.cs | 4 +- Source/SuperLinq/PartialSort.cs | 24 ++--- Source/SuperLinq/Permutations.cs | 10 +- Source/SuperLinq/Publish.cs | 4 +- Source/SuperLinq/RandomSubset.cs | 4 +- Source/SuperLinq/Repeat.cs | 6 +- Source/SuperLinq/Return.cs | 8 +- Source/SuperLinq/ScanRight.cs | 14 ++- Source/SuperLinq/Share.cs | 3 +- Source/SuperLinq/Shuffle.cs | 6 +- Source/SuperLinq/SkipUntil.cs | 2 +- Source/SuperLinq/SortedMerge.cs | 83 +++++++++++----- Source/SuperLinq/Split.cs | 53 +++++++--- Source/SuperLinq/StartsWith.cs | 8 +- Source/SuperLinq/Subsets.cs | 5 +- Source/SuperLinq/SuperEnumerable.cs | 3 +- Source/SuperLinq/TagFirstLast.cs | 6 +- Source/SuperLinq/Take.cs | 21 +--- Source/SuperLinq/Throw.cs | 2 +- Source/SuperLinq/ToDataTable.cs | 25 +++-- Source/SuperLinq/ToDelimitedString.cs | 6 +- Source/SuperLinq/Transpose.cs | 5 +- Source/SuperLinq/UnreachableException.cs | 9 +- Source/SuperLinq/Using.cs | 2 +- Source/SuperLinq/ValueTupleComparer.cs | 5 +- .../SuperLinq/ValueTupleEqualityComparer.cs | 17 ++-- Source/SuperLinq/WhereLag.cs | 9 +- Source/SuperLinq/WhereLead.cs | 22 ++++- Source/SuperLinq/Window.Buffered.Impl.cs | 12 ++- Source/SuperLinq/Window.cs | 3 +- Source/SuperLinq/WindowLeft.Buffered.cs | 8 +- Source/SuperLinq/WindowLeft.cs | 1 + Source/SuperLinq/WindowRight.cs | 7 +- Source/SuperLinq/ZipMap.cs | 7 +- Tests/SuperLinq.Async.Test/AggregateByTest.cs | 4 +- Tests/SuperLinq.Async.Test/AmbTest.cs | 6 +- Tests/SuperLinq.Async.Test/CatchTest.cs | 4 +- Tests/SuperLinq.Async.Test/CountDownTest.cs | 2 +- .../DensePartialSortByTest.cs | 4 +- Tests/SuperLinq.Async.Test/DuplicatesTest.cs | 10 +- Tests/SuperLinq.Async.Test/ElementAtTest.cs | 16 +-- Tests/SuperLinq.Async.Test/FoldTest.cs | 32 +++--- .../SuperLinq.Async.Test/FullOuterJoinTest.cs | 4 +- .../SuperLinq.Async.Test/HasDuplicatesTest.cs | 6 +- Tests/SuperLinq.Async.Test/InnerJoinTest.cs | 2 +- Tests/SuperLinq.Async.Test/InterleaveTest.cs | 2 +- Tests/SuperLinq.Async.Test/LagTest.cs | 2 +- Tests/SuperLinq.Async.Test/LeadTest.cs | 6 +- Tests/SuperLinq.Async.Test/LeftOuterJoin.cs | 2 +- Tests/SuperLinq.Async.Test/MemoizeTest.cs | 1 + .../OnErrorResumeNextTest.cs | 2 +- Tests/SuperLinq.Async.Test/OrderByTest.cs | 24 ++--- Tests/SuperLinq.Async.Test/PadStartTest.cs | 2 +- Tests/SuperLinq.Async.Test/PadTest.cs | 4 +- Tests/SuperLinq.Async.Test/ReplaceTest.cs | 2 +- Tests/SuperLinq.Async.Test/RightOuterJoin.cs | 2 +- Tests/SuperLinq.Async.Test/ScanRightTest.cs | 2 +- Tests/SuperLinq.Async.Test/SegmentTest.cs | 6 +- Tests/SuperLinq.Async.Test/SplitTest.cs | 2 +- Tests/SuperLinq.Async.Test/TakeTest.cs | 2 +- Tests/SuperLinq.Async.Test/TestingSequence.cs | 5 + Tests/SuperLinq.Async.Test/WhereLagTest.cs | 2 +- Tests/SuperLinq.Async.Test/WhereLeadTest.cs | 2 +- Tests/SuperLinq.Test/AggregateByTest.cs | 4 +- Tests/SuperLinq.Test/AggregateTest.cs | 2 +- Tests/SuperLinq.Test/AtLeastTest.cs | 12 +-- Tests/SuperLinq.Test/AtMostTest.cs | 12 +-- Tests/SuperLinq.Test/BatchTest.cs | 19 ++-- Tests/SuperLinq.Test/BreakingList.cs | 1 + Tests/SuperLinq.Test/CartesianTest.cs | 1 + Tests/SuperLinq.Test/CatchTest.cs | 4 +- Tests/SuperLinq.Test/CompareCountTest.cs | 2 +- Tests/SuperLinq.Test/CopyToTest.cs | 6 +- Tests/SuperLinq.Test/CountBetweenTest.cs | 2 +- Tests/SuperLinq.Test/CountDownTest.cs | 4 +- .../SuperLinq.Test/DensePartialSortByTest.cs | 4 +- Tests/SuperLinq.Test/DenseRankTest.cs | 14 +-- Tests/SuperLinq.Test/DuplicatesTest.cs | 10 +- Tests/SuperLinq.Test/ElementAtTest.cs | 2 +- Tests/SuperLinq.Test/EvaluateTest.cs | 4 +- Tests/SuperLinq.Test/ExactlyTest.cs | 12 +-- Tests/SuperLinq.Test/FlattenTest.cs | 2 +- Tests/SuperLinq.Test/FoldTest.cs | 32 +++--- Tests/SuperLinq.Test/FullOuterJoinTest.cs | 4 +- Tests/SuperLinq.Test/HasDuplicatesTest.cs | 6 +- Tests/SuperLinq.Test/InnerJoinTest.cs | 2 +- Tests/SuperLinq.Test/LagTest.cs | 8 +- Tests/SuperLinq.Test/LeadTest.cs | 8 +- Tests/SuperLinq.Test/LeftOuterJoin.cs | 2 +- Tests/SuperLinq.Test/MemoizeTest.cs | 3 +- Tests/SuperLinq.Test/MoveTest.cs | 2 +- Tests/SuperLinq.Test/OnErrorResumeNextTest.cs | 2 +- Tests/SuperLinq.Test/OrderByTest.cs | 24 ++--- Tests/SuperLinq.Test/PadStartTest.cs | 4 +- Tests/SuperLinq.Test/PadTest.cs | 4 +- Tests/SuperLinq.Test/PermutationsTest.cs | 4 +- Tests/SuperLinq.Test/RankTest.cs | 14 +-- Tests/SuperLinq.Test/ReplaceTest.cs | 2 +- Tests/SuperLinq.Test/RightOuterJoin.cs | 2 +- Tests/SuperLinq.Test/ScanRightTest.cs | 2 +- Tests/SuperLinq.Test/SegmentTest.cs | 6 +- Tests/SuperLinq.Test/SplitTest.cs | 2 +- Tests/SuperLinq.Test/SubsetTest.cs | 2 +- Tests/SuperLinq.Test/TakeTest.cs | 29 ++---- Tests/SuperLinq.Test/TestingSequence.cs | 12 +-- Tests/SuperLinq.Test/ToArrayByIndexTest.cs | 2 +- Tests/SuperLinq.Test/ToDataTableTest.cs | 15 ++- Tests/SuperLinq.Test/TrySingleTest.cs | 4 +- .../UpdatablePriorityQueueTest.cs | 10 -- Tests/SuperLinq.Test/WhereLagTest.cs | 2 +- Tests/SuperLinq.Test/WhereLeadTest.cs | 6 +- Tests/SuperLinq.Test/WindowLeftTest.cs | 9 +- Tests/SuperLinq.Test/WindowRightTest.cs | 9 +- Tests/SuperLinq.Test/WindowTest.cs | 9 +- Tests/SuperLinq.Test/ZipLongestTest.cs | 6 +- Tests/SuperLinq.Test/ZipMapTest.cs | 4 +- Tests/SuperLinq.Test/ZipShortestTest.cs | 6 +- 237 files changed, 2068 insertions(+), 1084 deletions(-) diff --git a/.editorconfig b/.editorconfig index 1755af052..e5edee47d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -46,6 +46,7 @@ dotnet_naming_rule.static_fields_should_be_camel_case.style = static_field_style dotnet_naming_symbols.static_fields.applicable_kinds = field dotnet_naming_symbols.static_fields.required_modifiers = static +dotnet_naming_symbols.static_fields.applicable_accessibilities = internal, private, private_protected # Instance fields are camelCase and start with _ dotnet_naming_rule.instance_fields_should_be_camel_case.severity = suggestion @@ -53,6 +54,7 @@ dotnet_naming_rule.instance_fields_should_be_camel_case.symbols = instance_field dotnet_naming_rule.instance_fields_should_be_camel_case.style = instance_field_style dotnet_naming_symbols.instance_fields.applicable_kinds = field +dotnet_naming_symbols.instance_fields.applicable_accessibilities = internal, private, private_protected # Locals and parameters are camelCase dotnet_naming_rule.locals_should_be_camel_case.severity = suggestion @@ -335,6 +337,7 @@ dotnet_diagnostic.RS2008.severity = none # RS2008: Enable analyze MA0053.public_class_should_be_sealed = true MA0053.exceptions_should_be_sealed = true +dotnet_diagnostic.MA0003.severity = suggestion dotnet_diagnostic.MA0004.severity = none dotnet_diagnostic.MA0005.severity = none dotnet_diagnostic.MA0006.severity = suggestion @@ -368,6 +371,7 @@ dotnet_diagnostic.MA0075.severity = none dotnet_diagnostic.MA0076.severity = none dotnet_diagnostic.MA0079.severity = none dotnet_diagnostic.MA0080.severity = none +dotnet_diagnostic.MA0084.severity = none dotnet_diagnostic.MA0094.severity = none dotnet_diagnostic.MA0095.severity = none dotnet_diagnostic.MA0096.severity = none @@ -385,6 +389,3 @@ dotnet_diagnostic.MA0147.severity = error dotnet_diagnostic.MA0148.severity = none dotnet_diagnostic.MA0149.severity = none dotnet_diagnostic.MA0154.severity = warning -dotnet_diagnostic.IDE0305.severity = suggestion -dotnet_diagnostic.MA0003.severity = suggestion -dotnet_diagnostic.MA0084.severity = none diff --git a/Generators/SuperLinq.Generator/ToDelimitedString.cs b/Generators/SuperLinq.Generator/ToDelimitedString.cs index 5c000c231..6cfcb09e4 100644 --- a/Generators/SuperLinq.Generator/ToDelimitedString.cs +++ b/Generators/SuperLinq.Generator/ToDelimitedString.cs @@ -17,12 +17,13 @@ public static SourceText Generate() .Select(p => p[0].ParameterType) .Where(t => !t.IsGenericType // e.g. ReadOnlySpan<> - && (t.IsValueType || t == typeof(string))) + && (t.IsValueType || t == typeof(string)) + ) .OrderBy(t => t.Name, StringComparer.Ordinal) .Select(t => $"global::{t.FullName}"); var template = Template.Parse(ThisAssembly.Resources.ToDelimitedString.Text); - var output = template.Render(new { Types = types.ToList(), }); + var output = template.Render(new { Types = types.ToList() }); // Apply formatting since indenting isn't that nice in Scriban when rendering nested // structures via functions. diff --git a/Source/SuperLinq.Async/AggregateRight.cs b/Source/SuperLinq.Async/AggregateRight.cs index 73f962b9f..1da4eead3 100644 --- a/Source/SuperLinq.Async/AggregateRight.cs +++ b/Source/SuperLinq.Async/AggregateRight.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -23,7 +23,11 @@ public static partial class AsyncSuperEnumerable /// /// This operator executes immediately. /// - public static ValueTask AggregateRight(this IAsyncEnumerable source, Func func, CancellationToken cancellationToken = default) + public static ValueTask AggregateRight( + this IAsyncEnumerable source, + Func func, + CancellationToken cancellationToken = default + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(func); @@ -52,7 +56,11 @@ public static ValueTask AggregateRight(this IAsyncEnumerable /// This operator executes immediately. /// - public static ValueTask AggregateRight(this IAsyncEnumerable source, Func> func, CancellationToken cancellationToken = default) + public static ValueTask AggregateRight( + this IAsyncEnumerable source, + Func> func, + CancellationToken cancellationToken = default + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(func); @@ -84,7 +92,8 @@ public static ValueTask AggregateRight(this IAsyncEnumerable AggregateRight( this IAsyncEnumerable source, Func> func, - CancellationToken cancellationToken = default) + CancellationToken cancellationToken = default + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(func); @@ -136,7 +145,12 @@ static async ValueTask Core( /// This operator executes immediately. /// - public static ValueTask AggregateRight(this IAsyncEnumerable source, TAccumulate seed, Func func, CancellationToken cancellationToken = default) + public static ValueTask AggregateRight( + this IAsyncEnumerable source, + TAccumulate seed, + Func func, + CancellationToken cancellationToken = default + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(func); @@ -170,7 +184,12 @@ public static ValueTask AggregateRight(this I /// This operator executes immediately. /// - public static ValueTask AggregateRight(this IAsyncEnumerable source, TAccumulate seed, Func> func, CancellationToken cancellationToken = default) + public static ValueTask AggregateRight( + this IAsyncEnumerable source, + TAccumulate seed, + Func> func, + CancellationToken cancellationToken = default + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(func); @@ -204,7 +223,12 @@ public static ValueTask AggregateRight(this I /// This operator executes immediately. /// - public static ValueTask AggregateRight(this IAsyncEnumerable source, TAccumulate seed, Func> func, CancellationToken cancellationToken = default) + public static ValueTask AggregateRight( + this IAsyncEnumerable source, + TAccumulate seed, + Func> func, + CancellationToken cancellationToken = default + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(func); @@ -254,12 +278,22 @@ static async ValueTask Core( /// This operator executes immediately. /// - public static ValueTask AggregateRight(this IAsyncEnumerable source, TAccumulate seed, Func func, Func resultSelector, CancellationToken cancellationToken = default) + public static ValueTask AggregateRight( + this IAsyncEnumerable source, + TAccumulate seed, + Func func, + Func resultSelector, + CancellationToken cancellationToken = default + ) { ArgumentNullException.ThrowIfNull(func); ArgumentNullException.ThrowIfNull(resultSelector); - return source.AggregateRight(seed, (a, b, ct) => new ValueTask(func(a, b)), (a, ct) => new ValueTask(resultSelector(a)), cancellationToken); + return source.AggregateRight( + seed, + (a, b, ct) => new ValueTask(func(a, b)), + (a, ct) => new ValueTask(resultSelector(a)), + cancellationToken); } /// @@ -292,7 +326,13 @@ public static ValueTask AggregateRight(t /// This operator executes immediately. /// - public static ValueTask AggregateRight(this IAsyncEnumerable source, TAccumulate seed, Func> func, Func> resultSelector, CancellationToken cancellationToken = default) + public static ValueTask AggregateRight( + this IAsyncEnumerable source, + TAccumulate seed, + Func> func, + Func> resultSelector, + CancellationToken cancellationToken = default + ) { ArgumentNullException.ThrowIfNull(func); ArgumentNullException.ThrowIfNull(resultSelector); @@ -330,7 +370,13 @@ public static ValueTask AggregateRight(t /// This operator executes immediately. /// - public static ValueTask AggregateRight(this IAsyncEnumerable source, TAccumulate seed, Func> func, Func> resultSelector, CancellationToken cancellationToken = default) + public static ValueTask AggregateRight( + this IAsyncEnumerable source, + TAccumulate seed, + Func> func, + Func> resultSelector, + CancellationToken cancellationToken = default + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(func); @@ -344,6 +390,7 @@ static async ValueTask Core( Func> func, Func> resultSelector, CancellationToken cancellationToken = default) => - await resultSelector(await source.AggregateRight(seed, func, cancellationToken).ConfigureAwait(false), cancellationToken).ConfigureAwait(false); + await resultSelector(await source.AggregateRight(seed, func, cancellationToken).ConfigureAwait(false), cancellationToken) + .ConfigureAwait(false); } } diff --git a/Source/SuperLinq.Async/AssertCount.cs b/Source/SuperLinq.Async/AssertCount.cs index c7dbef710..62c2e8e46 100644 --- a/Source/SuperLinq.Async/AssertCount.cs +++ b/Source/SuperLinq.Async/AssertCount.cs @@ -36,6 +36,7 @@ static async IAsyncEnumerable Core( { if (++c > count) break; + yield return item; } diff --git a/Source/SuperLinq.Async/AsyncSuperEnumerable.cs b/Source/SuperLinq.Async/AsyncSuperEnumerable.cs index 9a19dc701..df8da9adf 100644 --- a/Source/SuperLinq.Async/AsyncSuperEnumerable.cs +++ b/Source/SuperLinq.Async/AsyncSuperEnumerable.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; /// /// Provides a set of static methods for querying objects that @@ -6,8 +6,10 @@ /// public static partial class AsyncSuperEnumerable { - internal static ConfiguredCancelableAsyncEnumerable.Enumerator GetConfiguredAsyncEnumerator(this IAsyncEnumerable enumerable, CancellationToken cancellationToken) => - enumerable.ConfigureAwait(false).WithCancellation(cancellationToken).GetAsyncEnumerator(); + internal static ConfiguredCancelableAsyncEnumerable.Enumerator GetConfiguredAsyncEnumerator( + this IAsyncEnumerable enumerable, + CancellationToken cancellationToken + ) => enumerable.ConfigureAwait(false).WithCancellation(cancellationToken).GetAsyncEnumerator(); private static (bool HasValue, T Value) Some(T value) => (true, value); diff --git a/Source/SuperLinq.Async/BindByIndex.cs b/Source/SuperLinq.Async/BindByIndex.cs index 2fe19dca5..a180287ff 100644 --- a/Source/SuperLinq.Async/BindByIndex.cs +++ b/Source/SuperLinq.Async/BindByIndex.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -16,9 +16,18 @@ public static partial class AsyncSuperEnumerable /// An index in is out of range for the input sequence . public static IAsyncEnumerable BindByIndex( this IAsyncEnumerable source, - IAsyncEnumerable indices) + IAsyncEnumerable indices + ) { - return BindByIndex(source, indices, static (e, i) => e, static i => ThrowHelper.ThrowArgumentOutOfRangeException(nameof(indices), "Index is greater than the length of the first sequence.")); + return BindByIndex( + source, + indices, + static (e, i) => e, + static i => ThrowHelper.ThrowArgumentOutOfRangeException( + nameof(indices), + "Index is greater than the length of the first sequence." + ) + ); } /// @@ -47,7 +56,8 @@ public static IAsyncEnumerable BindByIndex( this IAsyncEnumerable source, IAsyncEnumerable indices, Func resultSelector, - Func missingSelector) + Func missingSelector + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(indices); @@ -57,11 +67,27 @@ public static IAsyncEnumerable BindByIndex( return Core(source, indices, resultSelector, missingSelector); static async IAsyncEnumerable Core( - IAsyncEnumerable source, IAsyncEnumerable indices, Func resultSelector, Func missingSelector, - [EnumeratorCancellation] CancellationToken cancellationToken = default) + IAsyncEnumerable source, + IAsyncEnumerable indices, + Func resultSelector, + Func missingSelector, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { // keeps track of the order of indices to know what order items should be output in - var lookup = await indices.Index().ToDictionaryAsync(x => { ArgumentOutOfRangeException.ThrowIfNegative(x.item, nameof(indices)); return x.item; }, x => x.index, cancellationToken).ConfigureAwait(false); + var lookup = await indices + .Index() + .ToDictionaryAsync( + x => + { + ArgumentOutOfRangeException.ThrowIfNegative(x.item, nameof(indices)); + return x.item; + }, + x => x.index, + cancellationToken + ) + .ConfigureAwait(false); + // keep track of items out of output order var lookback = new Dictionary(); diff --git a/Source/SuperLinq.Async/Catch.cs b/Source/SuperLinq.Async/Catch.cs index aadc0cb25..1aa589ffe 100644 --- a/Source/SuperLinq.Async/Catch.cs +++ b/Source/SuperLinq.Async/Catch.cs @@ -74,7 +74,7 @@ public static IAsyncEnumerable Catch(this IAsyncEnumerable diff --git a/Source/SuperLinq.Async/Choose.cs b/Source/SuperLinq.Async/Choose.cs index b515e5f7a..d1a780e92 100644 --- a/Source/SuperLinq.Async/Choose.cs +++ b/Source/SuperLinq.Async/Choose.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -31,7 +31,8 @@ public static partial class AsyncSuperEnumerable public static IAsyncEnumerable Choose( this IAsyncEnumerable source, - Func chooser) + Func chooser + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(chooser); @@ -68,7 +69,8 @@ public static IAsyncEnumerable Choose( public static IAsyncEnumerable Choose( this IAsyncEnumerable source, - Func> chooser) + Func> chooser + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(chooser); @@ -105,14 +107,19 @@ public static IAsyncEnumerable Choose( public static IAsyncEnumerable Choose( this IAsyncEnumerable source, - Func> chooser) + Func> chooser + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(chooser); return Core(source, chooser); - static async IAsyncEnumerable Core(IAsyncEnumerable source, Func> chooser, [EnumeratorCancellation] CancellationToken cancellationToken = default) + static async IAsyncEnumerable Core( + IAsyncEnumerable source, + Func> chooser, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { await foreach (var item in source.WithCancellation(cancellationToken).ConfigureAwait(false)) { diff --git a/Source/SuperLinq.Async/CollectionEqual.cs b/Source/SuperLinq.Async/CollectionEqual.cs index ffc73aa32..ed22713c1 100644 --- a/Source/SuperLinq.Async/CollectionEqual.cs +++ b/Source/SuperLinq.Async/CollectionEqual.cs @@ -25,7 +25,7 @@ public static partial class AsyncSuperEnumerable /// /// /// This method uses the default equality comparer for , , to - /// build a of the items from ; and + /// build a of the items from ; and /// compares the collection to using . /// /// @@ -66,7 +66,7 @@ public static ValueTask CollectionEqual( /// /// /// This method uses the provided equality comparer for to - /// build a of the items from ; and + /// build a of the items from ; and /// compares the collection to using . /// If is , the default equality comparer, /// , is used. diff --git a/Source/SuperLinq.Async/ConcurrentMerge.cs b/Source/SuperLinq.Async/ConcurrentMerge.cs index d4aa82ddf..0519c3841 100644 --- a/Source/SuperLinq.Async/ConcurrentMerge.cs +++ b/Source/SuperLinq.Async/ConcurrentMerge.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -105,8 +105,10 @@ void DisposeAsync(IAsyncEnumerator it) // since we're trying to round-robin, if current index // is after the iterator, we need to backtrack to account // for missing element in list - if (i > idx) i--; - else if (i >= list.Count) i = 0; + if (i > idx) + i--; + else if (i >= list.Count) + i = 0; // try to dispose var disposalTask = it.DisposeAsync(); diff --git a/Source/SuperLinq.Async/Consume.cs b/Source/SuperLinq.Async/Consume.cs index 8a464bb1f..a1328eded 100644 --- a/Source/SuperLinq.Async/Consume.cs +++ b/Source/SuperLinq.Async/Consume.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -17,9 +17,7 @@ public static ValueTask Consume(this IAsyncEnumerable source, Cancellation static async ValueTask Core(IAsyncEnumerable source, CancellationToken cancellationToken) { await foreach (var _ in source.WithCancellation(cancellationToken).ConfigureAwait(false)) - { cancellationToken.ThrowIfCancellationRequested(); - } } } } diff --git a/Source/SuperLinq.Async/CopyTo.cs b/Source/SuperLinq.Async/CopyTo.cs index 0d9242d4e..28fb8b554 100644 --- a/Source/SuperLinq.Async/CopyTo.cs +++ b/Source/SuperLinq.Async/CopyTo.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -22,7 +22,11 @@ public static partial class AsyncSuperEnumerable /// This operator executes immediately. /// /// - public static ValueTask CopyTo(this IAsyncEnumerable source, IList list, CancellationToken cancellationToken = default) + public static ValueTask CopyTo( + this IAsyncEnumerable source, + IList list, + CancellationToken cancellationToken = default + ) { return source.CopyTo(list, 0, cancellationToken); } @@ -49,7 +53,12 @@ public static ValueTask CopyTo(this IAsyncEnumerable sour /// This operator executes immediately. /// /// - public static async ValueTask CopyTo(this IAsyncEnumerable source, IList list, int index, CancellationToken cancellationToken = default) + public static async ValueTask CopyTo( + this IAsyncEnumerable source, + IList list, + int index, + CancellationToken cancellationToken = default + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(list); @@ -72,6 +81,7 @@ public static async ValueTask CopyTo(this IAsyncEnumerableFunction that transforms each item of source sequence into a key to be compared against the others. /// A sequence of unique keys and their number of occurrences in the original sequence. - public static IAsyncEnumerable> CountBy(this IAsyncEnumerable source, Func keySelector) + public static IAsyncEnumerable> CountBy( + this IAsyncEnumerable source, + Func keySelector + ) { return source.CountBy(keySelector, comparer: null); } @@ -30,14 +33,23 @@ public static IAsyncEnumerable> CountBy(t /// If null, the default equality comparer for is used. /// A sequence of unique keys and their number of occurrences in the original sequence. - public static IAsyncEnumerable> CountBy(this IAsyncEnumerable source, Func keySelector, IEqualityComparer? comparer) + public static IAsyncEnumerable> CountBy( + this IAsyncEnumerable source, + Func keySelector, + IEqualityComparer? comparer + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(keySelector); return Core(source, keySelector, comparer ?? EqualityComparer.Default); - static async IAsyncEnumerable> Core(IAsyncEnumerable source, Func keySelector, IEqualityComparer comparer, [EnumeratorCancellation] CancellationToken cancellationToken = default) + static async IAsyncEnumerable> Core( + IAsyncEnumerable source, + Func keySelector, + IEqualityComparer comparer, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { // Avoid the temptation to inline the Loop method, which // exists solely to separate the scope & lifetimes of the @@ -56,7 +68,12 @@ static async IAsyncEnumerable> Core(IAsyncEnumerable, List)> Loop(IAsyncEnumerable source, Func keySelector, IEqualityComparer cmp, CancellationToken cancellationToken) + static async ValueTask<(List, List)> Loop( + IAsyncEnumerable source, + Func keySelector, + IEqualityComparer cmp, + CancellationToken cancellationToken + ) { var dic = new Collections.NullKeyDictionary(cmp); diff --git a/Source/SuperLinq.Async/CountDown.cs b/Source/SuperLinq.Async/CountDown.cs index c7b3f79d9..52935b87e 100644 --- a/Source/SuperLinq.Async/CountDown.cs +++ b/Source/SuperLinq.Async/CountDown.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -13,7 +13,7 @@ public static partial class AsyncSuperEnumerable /// Count of tail elements of to count down. /// /// A sequence of tuples of the element and it's count from the end of the sequence. - /// + /// /// /// is . /// @@ -71,7 +71,8 @@ public static partial class AsyncSuperEnumerable /// public static IAsyncEnumerable CountDown( this IAsyncEnumerable source, - int count, Func resultSelector) + int count, Func resultSelector + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(resultSelector); @@ -79,7 +80,12 @@ public static IAsyncEnumerable CountDown( return Core(source, count, resultSelector); - static async IAsyncEnumerable Core(IAsyncEnumerable source, int count, Func resultSelector, [EnumeratorCancellation] CancellationToken cancellationToken = default) + static async IAsyncEnumerable Core( + IAsyncEnumerable source, + int count, + Func resultSelector, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { var queue = new Queue(Math.Max(1, count + 1)); diff --git a/Source/SuperLinq.Async/CountMethods.cs b/Source/SuperLinq.Async/CountMethods.cs index f1891eb25..4e54cf291 100644 --- a/Source/SuperLinq.Async/CountMethods.cs +++ b/Source/SuperLinq.Async/CountMethods.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -111,7 +111,12 @@ public static ValueTask Exactly(this IAsyncEnumerable source, int co /// The result variable will contain . /// - public static ValueTask CountBetween(this IAsyncEnumerable source, int min, int max, CancellationToken cancellationToken = default) + public static ValueTask CountBetween( + this IAsyncEnumerable source, + int min, + int max, + CancellationToken cancellationToken = default + ) { ArgumentNullException.ThrowIfNull(source); ArgumentOutOfRangeException.ThrowIfNegative(min); @@ -120,7 +125,13 @@ public static ValueTask CountBetween(this IAsyncEnumerable source, i return QuantityIterator(source, limit: max + 1, min: min, max: max, cancellationToken); } - private static async ValueTask QuantityIterator(IAsyncEnumerable source, int limit, int min, int max, CancellationToken cancellationToken) + private static async ValueTask QuantityIterator( + IAsyncEnumerable source, + int limit, + int min, + int max, + CancellationToken cancellationToken + ) { var count = 0; await foreach (var i in source.WithCancellation(cancellationToken).ConfigureAwait(false)) @@ -154,14 +165,22 @@ private static async ValueTask QuantityIterator(IAsyncEnumerable sou /// The result variable will contain 1. /// - public static ValueTask CompareCount(this IAsyncEnumerable first, IAsyncEnumerable second, CancellationToken cancellationToken = default) + public static ValueTask CompareCount( + this IAsyncEnumerable first, + IAsyncEnumerable second, + CancellationToken cancellationToken = default + ) { ArgumentNullException.ThrowIfNull(first); ArgumentNullException.ThrowIfNull(second); return Core(first, second, cancellationToken); - static async ValueTask Core(IAsyncEnumerable first, IAsyncEnumerable second, CancellationToken cancellationToken) + static async ValueTask Core( + IAsyncEnumerable first, + IAsyncEnumerable second, + CancellationToken cancellationToken + ) { bool firstHasNext; bool secondHasNext; diff --git a/Source/SuperLinq.Async/DensePartialSort.cs b/Source/SuperLinq.Async/DensePartialSort.cs index 8311da1c9..f9fb0c219 100644 --- a/Source/SuperLinq.Async/DensePartialSort.cs +++ b/Source/SuperLinq.Async/DensePartialSort.cs @@ -1,4 +1,4 @@ -using SuperLinq.Collections; +using SuperLinq.Collections; namespace SuperLinq.Async; @@ -51,7 +51,10 @@ public static IAsyncEnumerable DensePartialSort(this IAsyncEnumerable s /// /// public static IAsyncEnumerable DensePartialSort( - this IAsyncEnumerable source, int count, OrderByDirection direction) + this IAsyncEnumerable source, + int count, + OrderByDirection direction + ) { return source.DensePartialSort(count, comparer: null, direction); } @@ -79,7 +82,9 @@ public static IAsyncEnumerable DensePartialSort( /// public static IAsyncEnumerable DensePartialSort( this IAsyncEnumerable source, - int count, IComparer? comparer) + int count, + IComparer? comparer + ) { return DensePartialSort(source, count, comparer, OrderByDirection.Ascending); } @@ -107,8 +112,11 @@ public static IAsyncEnumerable DensePartialSort( /// /// public static IAsyncEnumerable DensePartialSort( - this IAsyncEnumerable source, int count, - IComparer? comparer, OrderByDirection direction) + this IAsyncEnumerable source, + int count, + IComparer? comparer, + OrderByDirection direction + ) { return DensePartialSortBy(source, count, Identity, comparer, direction); } @@ -121,8 +129,8 @@ public static IAsyncEnumerable DensePartialSort( /// Type of elements in the sequence. /// Type of keys. /// The source sequence. - /// A function to extract a key from an element. /// Number of (maximum) elements to return. + /// A function to extract a key from an element. /// A sequence containing at most top elements from source, in ascending order of /// their keys. /// is . @@ -137,8 +145,10 @@ public static IAsyncEnumerable DensePartialSort( /// /// public static IAsyncEnumerable DensePartialSortBy( - this IAsyncEnumerable source, int count, - Func keySelector) + this IAsyncEnumerable source, + int count, + Func keySelector + ) { return source.DensePartialSortBy(count, keySelector, comparer: null); } @@ -151,8 +161,8 @@ public static IAsyncEnumerable DensePartialSortBy( /// Type of elements in the sequence. /// Type of keys. /// The source sequence. - /// A function to extract a key from an element. /// Number of (maximum) elements to return. + /// A function to extract a key from an element. /// The direction in which to sort the elements /// A sequence containing at most top elements from source, in the specified order /// of their keys. @@ -168,8 +178,11 @@ public static IAsyncEnumerable DensePartialSortBy( /// /// public static IAsyncEnumerable DensePartialSortBy( - this IAsyncEnumerable source, int count, - Func keySelector, OrderByDirection direction) + this IAsyncEnumerable source, + int count, + Func keySelector, + OrderByDirection direction + ) { return source.DensePartialSortBy(count, keySelector, comparer: null, direction); } @@ -182,8 +195,8 @@ public static IAsyncEnumerable DensePartialSortBy( /// Type of elements in the sequence. /// Type of keys. /// The source sequence. - /// A function to extract a key from an element. /// Number of (maximum) elements to return. + /// A function to extract a key from an element. /// A to compare elements. /// A sequence containing at most top elements from source, in ascending order of /// their keys. @@ -201,7 +214,8 @@ public static IAsyncEnumerable DensePartialSortBy( public static IAsyncEnumerable DensePartialSortBy( this IAsyncEnumerable source, int count, Func keySelector, - IComparer? comparer) + IComparer? comparer + ) { return DensePartialSortBy(source, count, keySelector, comparer, OrderByDirection.Ascending); } @@ -215,8 +229,8 @@ public static IAsyncEnumerable DensePartialSortBy( /// Type of elements in the sequence. /// Type of keys. /// The source sequence. - /// A function to extract a key from an element. /// Number of (maximum) elements to return. + /// A function to extract a key from an element. /// A to compare elements. /// The direction in which to sort the elements /// A sequence containing at most top elements from source, in the specified order @@ -236,7 +250,8 @@ public static IAsyncEnumerable DensePartialSortBy( this IAsyncEnumerable source, int count, Func keySelector, IComparer? comparer, - OrderByDirection direction) + OrderByDirection direction + ) { ArgumentNullException.ThrowIfNull(source); ArgumentOutOfRangeException.ThrowIfNegativeOrZero(count); @@ -248,7 +263,13 @@ public static IAsyncEnumerable DensePartialSortBy( return Core(source, count, keySelector, comparer); - static async IAsyncEnumerable Core(IAsyncEnumerable source, int count, Func keySelector, IComparer comparer, [EnumeratorCancellation] CancellationToken cancellationToken = default) + static async IAsyncEnumerable Core( + IAsyncEnumerable source, + int count, + Func keySelector, + IComparer comparer, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { var top = new SortedSet(comparer); var dic = new NullKeyDictionary>(count); diff --git a/Source/SuperLinq.Async/DistinctBy.cs b/Source/SuperLinq.Async/DistinctBy.cs index 930907ca7..f40ddd8a4 100644 --- a/Source/SuperLinq.Async/DistinctBy.cs +++ b/Source/SuperLinq.Async/DistinctBy.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -21,7 +21,8 @@ public static partial class AsyncSuperEnumerable /// is . public static IAsyncEnumerable DistinctBy( this IAsyncEnumerable source, - Func keySelector) + Func keySelector + ) { return DistinctBy(source, keySelector, comparer: default); } @@ -48,14 +49,20 @@ public static IAsyncEnumerable DistinctBy( public static IAsyncEnumerable DistinctBy( this IAsyncEnumerable source, Func keySelector, - IEqualityComparer? comparer) + IEqualityComparer? comparer + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(keySelector); return Core(source, keySelector, comparer ?? EqualityComparer.Default); - static async IAsyncEnumerable Core(IAsyncEnumerable source, Func keySelector, IEqualityComparer comparer, [EnumeratorCancellation] CancellationToken cancellationToken = default) + static async IAsyncEnumerable Core( + IAsyncEnumerable source, + Func keySelector, + IEqualityComparer comparer, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { var knownKeys = new HashSet(comparer); await foreach (var element in source.WithCancellation(cancellationToken).ConfigureAwait(false)) diff --git a/Source/SuperLinq.Async/DistinctUntilChanged.cs b/Source/SuperLinq.Async/DistinctUntilChanged.cs index 513833f9b..6185d76e9 100644 --- a/Source/SuperLinq.Async/DistinctUntilChanged.cs +++ b/Source/SuperLinq.Async/DistinctUntilChanged.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -22,7 +22,10 @@ public static IAsyncEnumerable DistinctUntilChanged(this IAsyn /// Comparer used to compare values. /// Sequence without adjacent non-distinct elements. /// is . - public static IAsyncEnumerable DistinctUntilChanged(this IAsyncEnumerable source, IEqualityComparer? comparer) + public static IAsyncEnumerable DistinctUntilChanged( + this IAsyncEnumerable source, + IEqualityComparer? comparer + ) { ArgumentNullException.ThrowIfNull(source); return DistinctUntilChanged(source, Identity, comparer); @@ -39,7 +42,10 @@ public static IAsyncEnumerable DistinctUntilChanged(this IAsyn /// Sequence without adjacent non-distinct elements. /// or is . - public static IAsyncEnumerable DistinctUntilChanged(this IAsyncEnumerable source, Func keySelector) + public static IAsyncEnumerable DistinctUntilChanged( + this IAsyncEnumerable source, + Func keySelector + ) { ArgumentNullException.ThrowIfNull(keySelector); return DistinctUntilChanged(source, keySelector.ToAsync(), comparer: null); @@ -56,7 +62,10 @@ public static IAsyncEnumerable DistinctUntilChanged(this /// Sequence without adjacent non-distinct elements. /// or is . - public static IAsyncEnumerable DistinctUntilChanged(this IAsyncEnumerable source, Func> keySelector) + public static IAsyncEnumerable DistinctUntilChanged( + this IAsyncEnumerable source, + Func> keySelector + ) { return DistinctUntilChanged(source, keySelector, comparer: null); } @@ -72,7 +81,11 @@ public static IAsyncEnumerable DistinctUntilChanged(this /// Sequence without adjacent non-distinct elements. /// or is . - public static IAsyncEnumerable DistinctUntilChanged(this IAsyncEnumerable source, Func keySelector, IEqualityComparer? comparer) + public static IAsyncEnumerable DistinctUntilChanged( + this IAsyncEnumerable source, + Func keySelector, + IEqualityComparer? comparer + ) { ArgumentNullException.ThrowIfNull(keySelector); return DistinctUntilChanged(source, keySelector.ToAsync(), comparer); @@ -89,7 +102,11 @@ public static IAsyncEnumerable DistinctUntilChanged(this /// Sequence without adjacent non-distinct elements. /// or is . - public static IAsyncEnumerable DistinctUntilChanged(this IAsyncEnumerable source, Func> keySelector, IEqualityComparer? comparer) + public static IAsyncEnumerable DistinctUntilChanged( + this IAsyncEnumerable source, + Func> keySelector, + IEqualityComparer? comparer + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(keySelector); @@ -100,7 +117,8 @@ static async IAsyncEnumerable Core( IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer, - [EnumeratorCancellation] CancellationToken cancellationToken = default) + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { await using var e = source.GetConfiguredAsyncEnumerator(cancellationToken); if (!await e.MoveNextAsync()) diff --git a/Source/SuperLinq.Async/Do.cs b/Source/SuperLinq.Async/Do.cs index c63ddb5e3..2f8d64924 100644 --- a/Source/SuperLinq.Async/Do.cs +++ b/Source/SuperLinq.Async/Do.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -77,7 +77,11 @@ public static IAsyncEnumerable Do(this IAsyncEnumerable /// This method uses deferred execution and streams its results. /// - public static IAsyncEnumerable Do(this IAsyncEnumerable source, Func onNext, Func onCompleted) + public static IAsyncEnumerable Do( + this IAsyncEnumerable source, + Func onNext, + Func onCompleted + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(onNext); @@ -89,7 +93,8 @@ static async IAsyncEnumerable Core( IAsyncEnumerable source, Func onNext, Func onCompleted, - [EnumeratorCancellation] CancellationToken cancellationToken = default) + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { await foreach (var el in source .WithCancellation(cancellationToken) @@ -116,7 +121,11 @@ static async IAsyncEnumerable Core( /// /// This method uses deferred execution and streams its results. /// - public static IAsyncEnumerable Do(this IAsyncEnumerable source, Action onNext, Action onError) + public static IAsyncEnumerable Do( + this IAsyncEnumerable source, + Action onNext, + Action onError + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(onNext); @@ -138,7 +147,11 @@ public static IAsyncEnumerable Do(this IAsyncEnumerable /// This method uses deferred execution and streams its results. /// - public static IAsyncEnumerable Do(this IAsyncEnumerable source, Func onNext, Func onError) + public static IAsyncEnumerable Do( + this IAsyncEnumerable source, + Func onNext, + Func onError + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(onNext); @@ -162,7 +175,12 @@ public static IAsyncEnumerable Do(this IAsyncEnumerable /// This method uses deferred execution and streams its results. /// - public static IAsyncEnumerable Do(this IAsyncEnumerable source, Action onNext, Action onError, Action onCompleted) + public static IAsyncEnumerable Do( + this IAsyncEnumerable source, + Action onNext, + Action onError, + Action onCompleted + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(onNext); @@ -187,7 +205,12 @@ public static IAsyncEnumerable Do(this IAsyncEnumerable /// This method uses deferred execution and streams its results. /// - public static IAsyncEnumerable Do(this IAsyncEnumerable source, Func onNext, Func onError, Func onCompleted) + public static IAsyncEnumerable Do( + this IAsyncEnumerable source, + Func onNext, + Func onError, + Func onCompleted + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(onNext); @@ -201,7 +224,8 @@ static async IAsyncEnumerable Core( Func onNext, Func onError, Func onCompleted, - [EnumeratorCancellation] CancellationToken cancellationToken = default) + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { await using var iter = source.GetConfiguredAsyncEnumerator(cancellationToken); while (true) diff --git a/Source/SuperLinq.Async/DoWhile.cs b/Source/SuperLinq.Async/DoWhile.cs index 1fa4e8181..6542abc19 100644 --- a/Source/SuperLinq.Async/DoWhile.cs +++ b/Source/SuperLinq.Async/DoWhile.cs @@ -65,7 +65,8 @@ static async IAsyncEnumerable Core( { await foreach (var item in memo.WithCancellation(cancellationToken).ConfigureAwait(false)) yield return item; - } while (await condition().ConfigureAwait(false)); + } + while (await condition().ConfigureAwait(false)); } } } diff --git a/Source/SuperLinq.Async/Duplicates.cs b/Source/SuperLinq.Async/Duplicates.cs index ae22f88dd..b79284796 100644 --- a/Source/SuperLinq.Async/Duplicates.cs +++ b/Source/SuperLinq.Async/Duplicates.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -24,7 +24,10 @@ public static partial class AsyncSuperEnumerable /// /// This operator uses deferred execution and streams its results. /// - public static IAsyncEnumerable Duplicates(this IAsyncEnumerable source, IEqualityComparer? comparer = null) + public static IAsyncEnumerable Duplicates( + this IAsyncEnumerable source, + IEqualityComparer? comparer = null + ) { ArgumentNullException.ThrowIfNull(source); @@ -35,7 +38,8 @@ public static IAsyncEnumerable Duplicates(this IAsyncEnumerabl static async IAsyncEnumerable Core( IAsyncEnumerable source, IEqualityComparer comparer, - [EnumeratorCancellation] CancellationToken token = default) + [EnumeratorCancellation] CancellationToken token = default + ) { var counts = new Collections.NullKeyDictionary(comparer); await foreach (var element in source.WithCancellation(token).ConfigureAwait(false)) diff --git a/Source/SuperLinq.Async/ElementAt.cs b/Source/SuperLinq.Async/ElementAt.cs index 603e7bf5c..a55647c35 100644 --- a/Source/SuperLinq.Async/ElementAt.cs +++ b/Source/SuperLinq.Async/ElementAt.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. namespace SuperLinq.Async; @@ -15,18 +15,20 @@ public static partial class AsyncSuperEnumerable /// The element at the specified position in the sequence. /// /// - /// This method throws an exception if is out of range. - /// To instead return a default value when the specified index is out of range, + /// This method throws an exception if is out of range. + /// To instead return a default value when the specified index is out of range, /// use the method. /// - public static ValueTask ElementAtAsync(this IAsyncEnumerable source, Index index, CancellationToken cancellationToken = default) + public static ValueTask ElementAtAsync( + this IAsyncEnumerable source, + Index index, + CancellationToken cancellationToken = default + ) { ArgumentNullException.ThrowIfNull(source); if (!index.IsFromEnd) - { return AsyncEnumerable.ElementAtAsync(source, index.Value, cancellationToken); - } return Core(source, index, cancellationToken); @@ -34,9 +36,7 @@ static async ValueTask Core(IAsyncEnumerable source, Index ind { var (success, element) = await TryGetElementFromEnd(source, index.Value, cancellationToken).ConfigureAwait(false); if (!success) - { ThrowHelper.ThrowArgumentOutOfRangeException(nameof(index)); - } return Debug.AssertNotNull(element); } @@ -52,14 +52,16 @@ static async ValueTask Core(IAsyncEnumerable source, Index ind /// /// The default value for reference and nullable types is . /// - public static ValueTask ElementAtOrDefaultAsync(this IAsyncEnumerable source, Index index, CancellationToken cancellationToken = default) + public static ValueTask ElementAtOrDefaultAsync( + this IAsyncEnumerable source, + Index index, + CancellationToken cancellationToken = default + ) { ArgumentNullException.ThrowIfNull(source); if (!index.IsFromEnd) - { return AsyncEnumerable.ElementAtOrDefaultAsync(source, index.Value, cancellationToken); - } return Core(source, index, cancellationToken); @@ -70,7 +72,11 @@ static async ValueTask Core(IAsyncEnumerable source, Index ind } } - private static async ValueTask<(bool success, TSource? element)> TryGetElementFromEnd(IAsyncEnumerable source, int indexFromEnd, CancellationToken cancellationToken) + private static async ValueTask<(bool success, TSource? element)> TryGetElementFromEnd( + IAsyncEnumerable source, + int indexFromEnd, + CancellationToken cancellationToken + ) { if (indexFromEnd > 0) { @@ -82,17 +88,13 @@ static async ValueTask Core(IAsyncEnumerable source, Index ind while (await e.MoveNextAsync()) { if (queue.Count == indexFromEnd) - { _ = queue.Dequeue(); - } queue.Enqueue(e.Current); } if (queue.Count == indexFromEnd) - { return (true, queue.Dequeue()); - } } } diff --git a/Source/SuperLinq.Async/EndsWith.cs b/Source/SuperLinq.Async/EndsWith.cs index ae386112f..9a6c6090e 100644 --- a/Source/SuperLinq.Async/EndsWith.cs +++ b/Source/SuperLinq.Async/EndsWith.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -21,7 +21,11 @@ public static partial class AsyncSuperEnumerable /// on pairs of elements at /// the same index. /// - public static ValueTask EndsWith(this IAsyncEnumerable first, IEnumerable second, CancellationToken cancellationToken = default) + public static ValueTask EndsWith( + this IAsyncEnumerable first, + IEnumerable second, + CancellationToken cancellationToken = default + ) { ArgumentNullException.ThrowIfNull(first); ArgumentNullException.ThrowIfNull(second); @@ -48,7 +52,11 @@ public static ValueTask EndsWith(this IAsyncEnumerable first, IEnume /// on pairs of elements at /// the same index. /// - public static ValueTask EndsWith(this IAsyncEnumerable first, IAsyncEnumerable second, CancellationToken cancellationToken = default) + public static ValueTask EndsWith( + this IAsyncEnumerable first, + IAsyncEnumerable second, + CancellationToken cancellationToken = default + ) { return EndsWith(first, second, comparer: null, cancellationToken); } @@ -72,7 +80,12 @@ public static ValueTask EndsWith(this IAsyncEnumerable first, IAsync /// on pairs of /// elements at the same index. /// - public static ValueTask EndsWith(this IAsyncEnumerable first, IEnumerable second, IEqualityComparer? comparer, CancellationToken cancellationToken = default) + public static ValueTask EndsWith( + this IAsyncEnumerable first, + IEnumerable second, + IEqualityComparer? comparer, + CancellationToken cancellationToken = default + ) { ArgumentNullException.ThrowIfNull(first); ArgumentNullException.ThrowIfNull(second); @@ -99,7 +112,12 @@ public static ValueTask EndsWith(this IAsyncEnumerable first, IEnume /// on pairs of /// elements at the same index. /// - public static ValueTask EndsWith(this IAsyncEnumerable first, IAsyncEnumerable second, IEqualityComparer? comparer, CancellationToken cancellationToken = default) + public static ValueTask EndsWith( + this IAsyncEnumerable first, + IAsyncEnumerable second, + IEqualityComparer? comparer, + CancellationToken cancellationToken = default + ) { ArgumentNullException.ThrowIfNull(first); ArgumentNullException.ThrowIfNull(second); @@ -108,9 +126,17 @@ public static ValueTask EndsWith(this IAsyncEnumerable first, IAsync return Core(first, second, comparer, cancellationToken); - static async ValueTask Core(IAsyncEnumerable first, IAsyncEnumerable second, IEqualityComparer? comparer, CancellationToken cancellationToken) + static async ValueTask Core( + IAsyncEnumerable first, + IAsyncEnumerable second, + IEqualityComparer? comparer, + CancellationToken cancellationToken + ) { - var snd = await second.ToListAsync(cancellationToken).ConfigureAwait(false); + var snd = await second + .ToListAsync(cancellationToken) + .ConfigureAwait(false); + return await first.TakeLast(snd.Count) .SequenceEqualAsync( snd.ToAsyncEnumerable(), diff --git a/Source/SuperLinq.Async/EnumeratorList.cs b/Source/SuperLinq.Async/EnumeratorList.cs index f8015406f..aded95eef 100644 --- a/Source/SuperLinq.Async/EnumeratorList.cs +++ b/Source/SuperLinq.Async/EnumeratorList.cs @@ -11,6 +11,7 @@ internal static async ValueTask> Create(IEnumerable ExceptBy( this IAsyncEnumerable first, IAsyncEnumerable second, - Func keySelector) - => ExceptBy(first, second, keySelector, keyComparer: default); + Func keySelector + ) + { + return ExceptBy(first, second, keySelector, keyComparer: default); + } /// /// Returns the set of elements in the first sequence which aren't @@ -68,7 +71,8 @@ public static IAsyncEnumerable ExceptBy( static async IAsyncEnumerable Core( IAsyncEnumerable first, IAsyncEnumerable second, Func keySelector, IEqualityComparer? keyComparer, - [EnumeratorCancellation] CancellationToken cancellationToken = default) + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { var keys = await second.Select(keySelector).ToHashSetAsync(keyComparer, cancellationToken).ConfigureAwait(false); await foreach (var element in first.WithCancellation(cancellationToken).ConfigureAwait(false)) @@ -76,6 +80,7 @@ static async IAsyncEnumerable Core( var key = keySelector(element); if (keys.Contains(key)) continue; + yield return element; _ = keys.Add(key); } diff --git a/Source/SuperLinq.Async/FallbackIfEmpty.cs b/Source/SuperLinq.Async/FallbackIfEmpty.cs index 3465e08a2..1f357f6a8 100644 --- a/Source/SuperLinq.Async/FallbackIfEmpty.cs +++ b/Source/SuperLinq.Async/FallbackIfEmpty.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -64,14 +64,22 @@ public static IAsyncEnumerable FallbackIfEmpty(this IAsyncEnumerable so return Core(source, fallback); - static async IAsyncEnumerable Core(IAsyncEnumerable source, IAsyncEnumerable fallback, [EnumeratorCancellation] CancellationToken cancellationToken = default) + static async IAsyncEnumerable Core( + IAsyncEnumerable source, + IAsyncEnumerable fallback, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken)) { if (await e.MoveNextAsync()) { - do { yield return e.Current; } + do + { + yield return e.Current; + } while (await e.MoveNextAsync()); + yield break; } } diff --git a/Source/SuperLinq.Async/FillBackward.cs b/Source/SuperLinq.Async/FillBackward.cs index 137988d88..fb4ae40fa 100644 --- a/Source/SuperLinq.Async/FillBackward.cs +++ b/Source/SuperLinq.Async/FillBackward.cs @@ -102,7 +102,11 @@ public static IAsyncEnumerable FillBackward(this IAsyncEnumerable sourc /// they remain missing. /// - public static IAsyncEnumerable FillBackward(this IAsyncEnumerable source, Func predicate, Func fillSelector) + public static IAsyncEnumerable FillBackward( + this IAsyncEnumerable source, + Func predicate, + Func fillSelector + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(predicate); @@ -135,7 +139,11 @@ public static IAsyncEnumerable FillBackward(this IAsyncEnumerable sourc /// they remain missing. /// - public static IAsyncEnumerable FillBackward(this IAsyncEnumerable source, Func> predicate, Func fillSelector) + public static IAsyncEnumerable FillBackward( + this IAsyncEnumerable source, + Func> predicate, + Func fillSelector + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(predicate); @@ -168,7 +176,11 @@ public static IAsyncEnumerable FillBackward(this IAsyncEnumerable sourc /// they remain missing. /// - public static IAsyncEnumerable FillBackward(this IAsyncEnumerable source, Func predicate, Func> fillSelector) + public static IAsyncEnumerable FillBackward( + this IAsyncEnumerable source, + Func predicate, + Func> fillSelector + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(predicate); @@ -201,7 +213,11 @@ public static IAsyncEnumerable FillBackward(this IAsyncEnumerable sourc /// they remain missing. /// - public static IAsyncEnumerable FillBackward(this IAsyncEnumerable source, Func> predicate, Func> fillSelector) + public static IAsyncEnumerable FillBackward( + this IAsyncEnumerable source, + Func> predicate, + Func> fillSelector + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(predicate); @@ -210,7 +226,12 @@ public static IAsyncEnumerable FillBackward(this IAsyncEnumerable sourc return FillBackwardImpl(source, predicate, fillSelector); } - private static async IAsyncEnumerable FillBackwardImpl(IAsyncEnumerable source, Func> predicate, Func>? fillSelector, [EnumeratorCancellation] CancellationToken cancellationToken = default) + private static async IAsyncEnumerable FillBackwardImpl( + IAsyncEnumerable source, + Func> predicate, + Func>? fillSelector, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { List? blanks = null; diff --git a/Source/SuperLinq.Async/FillForward.cs b/Source/SuperLinq.Async/FillForward.cs index 96e0e6084..35604765b 100644 --- a/Source/SuperLinq.Async/FillForward.cs +++ b/Source/SuperLinq.Async/FillForward.cs @@ -101,8 +101,11 @@ public static IAsyncEnumerable FillForward(this IAsyncEnumerable source /// results. If elements are missing at the start of the sequence then /// they remain missing. /// - - public static IAsyncEnumerable FillForward(this IAsyncEnumerable source, Func predicate, Func fillSelector) + public static IAsyncEnumerable FillForward( + this IAsyncEnumerable source, + Func predicate, + Func fillSelector + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(predicate); @@ -134,8 +137,11 @@ public static IAsyncEnumerable FillForward(this IAsyncEnumerable source /// results. If elements are missing at the start of the sequence then /// they remain missing. /// - - public static IAsyncEnumerable FillForward(this IAsyncEnumerable source, Func> predicate, Func fillSelector) + public static IAsyncEnumerable FillForward( + this IAsyncEnumerable source, + Func> predicate, + Func fillSelector + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(predicate); @@ -167,8 +173,11 @@ public static IAsyncEnumerable FillForward(this IAsyncEnumerable source /// results. If elements are missing at the start of the sequence then /// they remain missing. /// - - public static IAsyncEnumerable FillForward(this IAsyncEnumerable source, Func predicate, Func> fillSelector) + public static IAsyncEnumerable FillForward( + this IAsyncEnumerable source, + Func predicate, + Func> fillSelector + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(predicate); @@ -201,7 +210,11 @@ public static IAsyncEnumerable FillForward(this IAsyncEnumerable source /// they remain missing. /// - public static IAsyncEnumerable FillForward(this IAsyncEnumerable source, Func> predicate, Func> fillSelector) + public static IAsyncEnumerable FillForward( + this IAsyncEnumerable source, + Func> predicate, + Func> fillSelector + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(predicate); @@ -210,7 +223,11 @@ public static IAsyncEnumerable FillForward(this IAsyncEnumerable source return FillForwardImpl(source, predicate, fillSelector); } - private static async IAsyncEnumerable FillForwardImpl(IAsyncEnumerable source, Func> predicate, Func>? fillSelector, [EnumeratorCancellation] CancellationToken cancellationToken = default) + private static async IAsyncEnumerable FillForwardImpl( + IAsyncEnumerable source, + Func> predicate, + Func>? fillSelector, + [EnumeratorCancellation] CancellationToken cancellationToken = default) { (bool, T) seed = default; diff --git a/Source/SuperLinq.Async/FindIndex.cs b/Source/SuperLinq.Async/FindIndex.cs index 6eb2f9133..8fc52fedd 100644 --- a/Source/SuperLinq.Async/FindIndex.cs +++ b/Source/SuperLinq.Async/FindIndex.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -26,13 +26,17 @@ public static partial class AsyncSuperEnumerable /// /// The is a delegate to a method that returns if the object /// passed to it matches the conditions defined in the delegate. The elements of the current are individually passed to the delegate. + /// cref="IAsyncEnumerable{T}"/> are individually passed to the delegate. /// /// /// This operator executes immediately. /// /// - public static ValueTask FindIndex(this IAsyncEnumerable source, Func predicate, CancellationToken cancellationToken = default) + public static ValueTask FindIndex( + this IAsyncEnumerable source, + Func predicate, + CancellationToken cancellationToken = default + ) { return source.FindIndex(predicate, 0, int.MaxValue, cancellationToken); } @@ -64,13 +68,18 @@ public static ValueTask FindIndex(this IAsyncEnumerable s /// /// The is a delegate to a method that returns if the object /// passed to it matches the conditions defined in the delegate. The elements of the current are individually passed to the delegate. + /// cref="IAsyncEnumerable{T}"/> are individually passed to the delegate. /// /// /// This operator executes immediately. /// /// - public static ValueTask FindIndex(this IAsyncEnumerable source, Func predicate, Index index, CancellationToken cancellationToken = default) + public static ValueTask FindIndex( + this IAsyncEnumerable source, + Func predicate, + Index index, + CancellationToken cancellationToken = default + ) { return source.FindIndex(predicate, index, int.MaxValue, cancellationToken); } @@ -105,13 +114,19 @@ public static ValueTask FindIndex(this IAsyncEnumerable s /// /// The is a delegate to a method that returns if the object /// passed to it matches the conditions defined in the delegate. The elements of the current are individually passed to the delegate. + /// cref="IAsyncEnumerable{T}"/> are individually passed to the delegate. /// /// /// This operator executes immediately. /// /// - public static ValueTask FindIndex(this IAsyncEnumerable source, Func predicate, Index index, int count, CancellationToken cancellationToken = default) + public static ValueTask FindIndex( + this IAsyncEnumerable source, + Func predicate, + Index index, + int count, + CancellationToken cancellationToken = default + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(predicate); @@ -119,7 +134,13 @@ public static ValueTask FindIndex(this IAsyncEnumerable s return Core(source, predicate, index, count, cancellationToken); - static async ValueTask Core(IAsyncEnumerable source, Func predicate, Index index, int count, CancellationToken cancellationToken) + static async ValueTask Core( + IAsyncEnumerable source, + Func predicate, + Index index, + int count, + CancellationToken cancellationToken + ) { if (!index.IsFromEnd) { @@ -131,6 +152,7 @@ static async ValueTask Core(IAsyncEnumerable source, Func= count) return -1; } @@ -167,8 +189,10 @@ static async ValueTask Core(IAsyncEnumerable source, Func= count) return -1; + i++; } } diff --git a/Source/SuperLinq.Async/FindLastIndex.cs b/Source/SuperLinq.Async/FindLastIndex.cs index a7cf68989..83dad504e 100644 --- a/Source/SuperLinq.Async/FindLastIndex.cs +++ b/Source/SuperLinq.Async/FindLastIndex.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -27,13 +27,17 @@ public static partial class AsyncSuperEnumerable /// /// The is a delegate to a method that returns if the object /// passed to it matches the conditions defined in the delegate. The elements of the current are individually passed to the delegate. + /// cref="IAsyncEnumerable{T}"/> are individually passed to the delegate. /// /// /// This operator executes immediately. /// /// - public static ValueTask FindLastIndex(this IAsyncEnumerable source, Func predicate, CancellationToken cancellationToken = default) + public static ValueTask FindLastIndex( + this IAsyncEnumerable source, + Func predicate, + CancellationToken cancellationToken = default + ) { return source.FindLastIndex(predicate, ^1, int.MaxValue, cancellationToken); } @@ -66,13 +70,18 @@ public static ValueTask FindLastIndex(this IAsyncEnumerable /// The is a delegate to a method that returns if the object /// passed to it matches the conditions defined in the delegate. The elements of the current are individually passed to the delegate. + /// cref="IAsyncEnumerable{T}"/> are individually passed to the delegate. /// /// /// This operator executes immediately. /// /// - public static ValueTask FindLastIndex(this IAsyncEnumerable source, Func predicate, Index index, CancellationToken cancellationToken = default) + public static ValueTask FindLastIndex( + this IAsyncEnumerable source, + Func predicate, + Index index, + CancellationToken cancellationToken = default + ) { return source.FindLastIndex(predicate, index, int.MaxValue, cancellationToken); } @@ -109,13 +118,19 @@ public static ValueTask FindLastIndex(this IAsyncEnumerable /// The is a delegate to a method that returns if the object /// passed to it matches the conditions defined in the delegate. The elements of the current are individually passed to the delegate. + /// cref="IAsyncEnumerable{T}"/> are individually passed to the delegate. /// /// /// This operator executes immediately. /// /// - public static ValueTask FindLastIndex(this IAsyncEnumerable source, Func predicate, Index index, int count, CancellationToken cancellationToken = default) + public static ValueTask FindLastIndex( + this IAsyncEnumerable source, + Func predicate, + Index index, + int count, + CancellationToken cancellationToken = default + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(predicate); @@ -123,7 +138,13 @@ public static ValueTask FindLastIndex(this IAsyncEnumerable Core(IAsyncEnumerable source, Func predicate, Index index, int count, CancellationToken cancellationToken) + static async ValueTask Core( + IAsyncEnumerable source, + Func predicate, + Index index, + int count, + CancellationToken cancellationToken + ) { if (!index.IsFromEnd) { @@ -136,6 +157,7 @@ static async ValueTask Core(IAsyncEnumerable source, Func From(Func> function) ArgumentNullException.ThrowIfNull(function); return Core(function); - static async IAsyncEnumerable Core(Func> function, [EnumeratorCancellation] CancellationToken cancellationToken = default) + static async IAsyncEnumerable Core( + Func> function, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { cancellationToken.ThrowIfCancellationRequested(); yield return await function().ConfigureAwait(false); @@ -45,7 +48,11 @@ public static IAsyncEnumerable From(Func> function1, Func> ArgumentNullException.ThrowIfNull(function2); return Core(function1, function2); - static async IAsyncEnumerable Core(Func> function1, Func> function2, [EnumeratorCancellation] CancellationToken cancellationToken = default) + static async IAsyncEnumerable Core( + Func> function1, + Func> function2, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { cancellationToken.ThrowIfCancellationRequested(); yield return await function1().ConfigureAwait(false); @@ -75,7 +82,12 @@ public static IAsyncEnumerable From(Func> function1, Func> ArgumentNullException.ThrowIfNull(function3); return Core(function1, function2, function3); - static async IAsyncEnumerable Core(Func> function1, Func> function2, Func> function3, [EnumeratorCancellation] CancellationToken cancellationToken = default) + static async IAsyncEnumerable Core( + Func> function1, + Func> function2, + Func> function3, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { cancellationToken.ThrowIfCancellationRequested(); yield return await function1().ConfigureAwait(false); @@ -120,7 +132,9 @@ public static IAsyncEnumerable Evaluate(this IEnumerable>> fu ArgumentNullException.ThrowIfNull(functions); return Core(functions); - static async IAsyncEnumerable Core(IEnumerable>> functions, [EnumeratorCancellation] CancellationToken cancellationToken = default) + static async IAsyncEnumerable Core( + IEnumerable>> functions, + [EnumeratorCancellation] CancellationToken cancellationToken = default) { foreach (var f in functions) { @@ -148,12 +162,13 @@ public static IAsyncEnumerable Evaluate(this IAsyncEnumerable ArgumentNullException.ThrowIfNull(functions); return Core(functions); - static async IAsyncEnumerable Core(IAsyncEnumerable>> functions, [EnumeratorCancellation] CancellationToken cancellationToken = default) + static async IAsyncEnumerable Core( + IAsyncEnumerable>> functions, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { await foreach (var f in functions.WithCancellation(cancellationToken).ConfigureAwait(false)) - { yield return await f().ConfigureAwait(false); - } } } } diff --git a/Source/SuperLinq.Async/Generate.cs b/Source/SuperLinq.Async/Generate.cs index 6b04a91da..dfee25722 100644 --- a/Source/SuperLinq.Async/Generate.cs +++ b/Source/SuperLinq.Async/Generate.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -52,7 +52,11 @@ public static IAsyncEnumerable Generate(TResult initial, Func< return Core(initial, generator); - static async IAsyncEnumerable Core(TResult current, Func> generator, [EnumeratorCancellation] CancellationToken cancellationToken = default) + static async IAsyncEnumerable Core( + TResult current, + Func> generator, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { while (true) { diff --git a/Source/SuperLinq.Async/GetShortestPath.cs b/Source/SuperLinq.Async/GetShortestPath.cs index b5db2a014..c4aa54ca6 100644 --- a/Source/SuperLinq.Async/GetShortestPath.cs +++ b/Source/SuperLinq.Async/GetShortestPath.cs @@ -18,7 +18,7 @@ public partial class AsyncSuperEnumerable /// The starting state /// /// A function that returns the neighbors for a given state - /// and the total cost to get to that state based on the + /// and the total cost to get to that state based on the /// traversal cost at the current state. /// /// The target state @@ -50,13 +50,13 @@ public partial class AsyncSuperEnumerable /// will have undefined behavior. /// /// - /// This method will operate on an infinite map, however, + /// This method will operate on an infinite map, however, /// performance will depend on how many states are required to /// be evaluated before reaching the target point. /// /// /// This method uses - /// to compare s and + /// to compare s and /// to compare traversal /// s. /// @@ -89,7 +89,7 @@ public partial class AsyncSuperEnumerable /// The starting state /// /// A function that returns the neighbors for a given state - /// and the total cost to get to that state based on the + /// and the total cost to get to that state based on the /// traversal cost at the current state. /// /// The target state @@ -123,7 +123,7 @@ public partial class AsyncSuperEnumerable /// will have undefined behavior. /// /// - /// This method will operate on an infinite map, however, + /// This method will operate on an infinite map, however, /// performance will depend on how many states are required to /// be evaluated before reaching the target point. /// @@ -305,7 +305,8 @@ public partial class AsyncSuperEnumerable if (!queue.TryDequeue(out current, out cost)) ThrowHelper.ThrowInvalidOperationException("Unable to find path to 'end'."); - } while (true); + } + while (true); return cost; } @@ -325,7 +326,7 @@ public partial class AsyncSuperEnumerable /// The starting state /// /// A function that returns the neighbors for a given state - /// and the total cost to get to that state based on the + /// and the total cost to get to that state based on the /// traversal cost at the current state. /// /// The target state @@ -357,13 +358,13 @@ public partial class AsyncSuperEnumerable /// will have undefined behavior. /// /// - /// This method will operate on an infinite map, however, + /// This method will operate on an infinite map, however, /// performance will depend on how many states are required to /// be evaluated before reaching the target point. /// /// /// This method uses - /// to compare s and + /// to compare s and /// to compare traversal /// s. /// @@ -399,7 +400,7 @@ public partial class AsyncSuperEnumerable /// The starting state /// /// A function that returns the neighbors for a given state - /// and the total cost to get to that state based on the + /// and the total cost to get to that state based on the /// traversal cost at the current state. /// /// The target state @@ -433,7 +434,7 @@ public partial class AsyncSuperEnumerable /// will have undefined behavior. /// /// - /// This method will operate on an infinite map, however, + /// This method will operate on an infinite map, however, /// performance will depend on how many states are required to /// be evaluated before reaching the target point. /// @@ -630,7 +631,8 @@ public partial class AsyncSuperEnumerable if (!queue.TryDequeue(out current, out from)) ThrowHelper.ThrowInvalidOperationException("Unable to find path to 'end'."); - } while (true); + } + while (true); return SuperEnumerable.Generate(end, x => totalCost[x].parent!) .TakeUntil(x => stateComparer.Equals(x, start)) @@ -645,7 +647,7 @@ public partial class AsyncSuperEnumerable #region Full Map Cost /// - /// Find the shortest path from state + /// Find the shortest path from state /// to every other in the map, /// using Dijkstra's algorithm. /// @@ -654,7 +656,7 @@ public partial class AsyncSuperEnumerable /// The starting state /// /// A function that returns the neighbors for a given state - /// and the total cost to get to that state based on the + /// and the total cost to get to that state based on the /// traversal cost at the current state. /// /// The optional cancellation token to be used for cancelling the sequence at any time. @@ -670,7 +672,7 @@ public partial class AsyncSuperEnumerable /// /// This method uses Dijkstra's algorithm to explore a map /// and find the shortest path from - /// to every other in the map. + /// to every other in the map. /// An /// is used to manage the list of s /// to process, to reduce the computation cost of this operator. @@ -698,7 +700,7 @@ public partial class AsyncSuperEnumerable /// /// /// This method uses - /// to compare s and + /// to compare s and /// to compare traversal /// s. /// @@ -723,7 +725,7 @@ public partial class AsyncSuperEnumerable } /// - /// Find the shortest path from state + /// Find the shortest path from state /// to every other in the map, /// using Dijkstra's algorithm. /// @@ -732,7 +734,7 @@ public partial class AsyncSuperEnumerable /// The starting state /// /// A function that returns the neighbors for a given state - /// and the total cost to get to that state based on the + /// and the total cost to get to that state based on the /// traversal cost at the current state. /// /// A custom equality comparer for @@ -750,7 +752,7 @@ public partial class AsyncSuperEnumerable /// /// This method uses Dijkstra's algorithm to explore a map /// and find the shortest path from - /// to every other in the map. + /// to every other in the map. /// An /// is used to manage the list of s /// to process, to reduce the computation cost of this operator. @@ -828,7 +830,8 @@ public partial class AsyncSuperEnumerable if (!totalCost.TryGetValue(s, out _)) queue.EnqueueMinimum(s, (current, p)); } - } while (queue.TryDequeue(out current, out from)); + } + while (queue.TryDequeue(out current, out from)); return totalCost; } @@ -852,7 +855,7 @@ public partial class AsyncSuperEnumerable /// The starting state /// /// A function that returns the neighbors for a given state; - /// the total cost to get to that state based on the + /// the total cost to get to that state based on the /// traversal cost at the current state; and the predicted /// or best-guess total (already traversed plus remaining) /// cost to get to . @@ -888,13 +891,13 @@ public partial class AsyncSuperEnumerable /// will have undefined behavior. /// /// - /// This method will operate on an infinite map, however, + /// This method will operate on an infinite map, however, /// performance will depend on how many states are required to /// be evaluated before reaching the target point. /// /// /// This method uses - /// to compare s and + /// to compare s and /// to compare traversal /// s. /// @@ -929,7 +932,7 @@ public partial class AsyncSuperEnumerable /// The starting state /// /// A function that returns the neighbors for a given state; - /// the total cost to get to that state based on the + /// the total cost to get to that state based on the /// traversal cost at the current state; and the predicted /// or best-guess total (already traversed plus remaining) /// cost to get to . @@ -967,7 +970,7 @@ public partial class AsyncSuperEnumerable /// will have undefined behavior. /// /// - /// This method will operate on an infinite map, however, + /// This method will operate on an infinite map, however, /// performance will depend on how many states are required to /// be evaluated before reaching the target point. /// @@ -1164,7 +1167,8 @@ public partial class AsyncSuperEnumerable if (!queue.TryDequeue(out current, out costs)) ThrowHelper.ThrowInvalidOperationException("Unable to find path to 'end'."); - } while (true); + } + while (true); return costs.traversed; } @@ -1184,7 +1188,7 @@ public partial class AsyncSuperEnumerable /// The starting state /// /// A function that returns the neighbors for a given state; - /// the total cost to get to that state based on the + /// the total cost to get to that state based on the /// traversal cost at the current state; and the predicted /// or best-guess total (already traversed plus remaining) /// cost to get to . @@ -1220,13 +1224,13 @@ public partial class AsyncSuperEnumerable /// will have undefined behavior. /// /// - /// This method will operate on an infinite map, however, + /// This method will operate on an infinite map, however, /// performance will depend on how many states are required to /// be evaluated before reaching the target point. /// /// /// This method uses - /// to compare s and + /// to compare s and /// to compare traversal /// s. /// @@ -1262,7 +1266,7 @@ public partial class AsyncSuperEnumerable /// The starting state /// /// A function that returns the neighbors for a given state; - /// the total cost to get to that state based on the + /// the total cost to get to that state based on the /// traversal cost at the current state; and the predicted /// or best-guess total (already traversed plus remaining) /// cost to get to . @@ -1300,7 +1304,7 @@ public partial class AsyncSuperEnumerable /// will have undefined behavior. /// /// - /// This method will operate on an infinite map, however, + /// This method will operate on an infinite map, however, /// performance will depend on how many states are required to /// be evaluated before reaching the target point. /// @@ -1516,7 +1520,8 @@ public partial class AsyncSuperEnumerable if (!queue.TryDequeue(out current, out from)) ThrowHelper.ThrowInvalidOperationException("Unable to find path to 'end'."); - } while (true); + } + while (true); return SuperEnumerable.Generate(end, x => totalCost[x].parent!) .TakeUntil(x => stateComparer.Equals(x, start)) diff --git a/Source/SuperLinq.Async/GroupAdjacent.cs b/Source/SuperLinq.Async/GroupAdjacent.cs index b54a0f47c..e436458cd 100644 --- a/Source/SuperLinq.Async/GroupAdjacent.cs +++ b/Source/SuperLinq.Async/GroupAdjacent.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections; namespace SuperLinq.Async; @@ -270,7 +270,7 @@ private static async IAsyncEnumerable GroupAdjacentImpl() { elementSelector(iterator.Current), }; + var members = new List() { elementSelector(iterator.Current) }; while (await iterator.MoveNextAsync()) { @@ -280,7 +280,6 @@ private static async IAsyncEnumerable GroupAdjacentImplThe sequence to check. /// The type of the elements in the source sequence /// - /// if any element of the sequence is duplicated, otherwise + /// if any element of the sequence is duplicated, otherwise /// public static ValueTask HasDuplicates(this IAsyncEnumerable source) { @@ -23,7 +23,7 @@ public static ValueTask HasDuplicates(this IAsyncEnumerable source) /// If null, the default equality comparer for TSource is used. /// The type of the elements in the source sequence /// - /// if any element of the sequence is duplicated, otherwise + /// if any element of the sequence is duplicated, otherwise /// public static ValueTask HasDuplicates(this IAsyncEnumerable source, IEqualityComparer? comparer) { @@ -38,7 +38,7 @@ public static ValueTask HasDuplicates(this IAsyncEnumerable source, /// Type of the source sequence /// Type of the projected element /// - /// if any element of the sequence is duplicated, otherwise + /// if any element of the sequence is duplicated, otherwise /// public static ValueTask HasDuplicates(this IAsyncEnumerable source, Func keySelector) { @@ -55,9 +55,13 @@ public static ValueTask HasDuplicates(this IAsyncEnumerable /// Type of the source sequence /// Type of the projected element /// - /// if any element of the sequence is duplicated, otherwise + /// if any element of the sequence is duplicated, otherwise /// - public static ValueTask HasDuplicates(this IAsyncEnumerable source, Func keySelector, IEqualityComparer? comparer) + public static ValueTask HasDuplicates( + this IAsyncEnumerable source, + Func keySelector, + IEqualityComparer? comparer + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(keySelector); diff --git a/Source/SuperLinq.Async/Index.cs b/Source/SuperLinq.Async/Index.cs index 451e99293..5ffecfbc3 100644 --- a/Source/SuperLinq.Async/Index.cs +++ b/Source/SuperLinq.Async/Index.cs @@ -3,7 +3,7 @@ public static partial class AsyncSuperEnumerable { /// - /// Returns a sequence of tuples where the `key` is + /// Returns a sequence of tuples where the `key` is /// the zero-based index of the `value` in the source /// sequence. /// @@ -18,9 +18,9 @@ public static partial class AsyncSuperEnumerable } /// - /// Returns a sequence of tuples where the `key` is + /// Returns a sequence of tuples where the `key` is /// the zero-based index of the `value` in the source - /// sequence. An additional parameter specifies the + /// sequence. An additional parameter specifies the /// starting index. /// /// Type of elements in sequence. diff --git a/Source/SuperLinq.Async/IndexOf.cs b/Source/SuperLinq.Async/IndexOf.cs index 264d0ace2..5cd5bcdfa 100644 --- a/Source/SuperLinq.Async/IndexOf.cs +++ b/Source/SuperLinq.Async/IndexOf.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -31,7 +31,11 @@ public static partial class AsyncSuperEnumerable /// This operator executes immediately. /// /// - public static ValueTask IndexOf(this IAsyncEnumerable source, TSource item, CancellationToken cancellationToken = default) + public static ValueTask IndexOf( + this IAsyncEnumerable source, + TSource item, + CancellationToken cancellationToken = default + ) { return source.IndexOf(item, 0, int.MaxValue, cancellationToken); } @@ -67,7 +71,12 @@ public static ValueTask IndexOf(this IAsyncEnumerable sou /// This operator executes immediately. /// /// - public static ValueTask IndexOf(this IAsyncEnumerable source, TSource item, Index index, CancellationToken cancellationToken = default) + public static ValueTask IndexOf( + this IAsyncEnumerable source, + TSource item, + Index index, + CancellationToken cancellationToken = default + ) { return source.IndexOf(item, index, int.MaxValue, cancellationToken); } @@ -106,7 +115,13 @@ public static ValueTask IndexOf(this IAsyncEnumerable sou /// This operator executes immediately. /// /// - public static ValueTask IndexOf(this IAsyncEnumerable source, TSource item, Index index, int count, CancellationToken cancellationToken = default) + public static ValueTask IndexOf( + this IAsyncEnumerable source, + TSource item, + Index index, + int count, + CancellationToken cancellationToken = default + ) { return FindIndex(source, i => EqualityComparer.Default.Equals(i, item), index, count, cancellationToken); } diff --git a/Source/SuperLinq.Async/Insert.cs b/Source/SuperLinq.Async/Insert.cs index 8b386162f..3047a5202 100644 --- a/Source/SuperLinq.Async/Insert.cs +++ b/Source/SuperLinq.Async/Insert.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -36,7 +36,12 @@ public static IAsyncEnumerable Insert(this IAsyncEnumerable first, IAsy return Core(first, second, index); - static async IAsyncEnumerable Core(IAsyncEnumerable first, IAsyncEnumerable second, int index, [EnumeratorCancellation] CancellationToken cancellationToken = default) + static async IAsyncEnumerable Core( + IAsyncEnumerable first, + IAsyncEnumerable second, + int index, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { var i = -1; @@ -95,7 +100,12 @@ public static IAsyncEnumerable Insert(this IAsyncEnumerable first, IAsy index.Value == 0 ? first.Concat(second) : Core(first, second, index.Value); - static async IAsyncEnumerable Core(IAsyncEnumerable first, IAsyncEnumerable second, int index, [EnumeratorCancellation] CancellationToken cancellationToken = default) + static async IAsyncEnumerable Core( + IAsyncEnumerable first, + IAsyncEnumerable second, + int index, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { await using var e = first.CountDown(index, ValueTuple.Create).GetConfiguredAsyncEnumerator(cancellationToken); diff --git a/Source/SuperLinq.Async/Interleave.cs b/Source/SuperLinq.Async/Interleave.cs index 2c6fe93d4..cd2202476 100644 --- a/Source/SuperLinq.Async/Interleave.cs +++ b/Source/SuperLinq.Async/Interleave.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -56,7 +56,10 @@ public static IAsyncEnumerable Interleave(this IEnumerable Core(IEnumerable> sources, [EnumeratorCancellation] CancellationToken cancellationToken = default) + static async IAsyncEnumerable Core( + IEnumerable> sources, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { var list = await EnumeratorList.Create(sources, cancellationToken).ConfigureAwait(false); await using var ignored_ = list.ConfigureAwait(false); @@ -64,9 +67,7 @@ static async IAsyncEnumerable Core(IEnumerable> sources, while (list.Any()) { for (var i = 0; await list.MoveNext(i).ConfigureAwait(false); i++) - { yield return list.Current(i); - } } } } diff --git a/Source/SuperLinq.Async/Join.HashJoin.cs b/Source/SuperLinq.Async/Join.HashJoin.cs index 912b25517..ce7c32148 100644 --- a/Source/SuperLinq.Async/Join.HashJoin.cs +++ b/Source/SuperLinq.Async/Join.HashJoin.cs @@ -648,6 +648,7 @@ private static async IAsyncEnumerable JoinHash JoinMerge JoinMerge (curr.Value, lag is (true, var some) ? some : default)); + return source + .Select(Some) + .Lag(offset, default, (curr, lag) => (curr.Value, lag is (true, var some) ? some : default)); } /// @@ -36,13 +37,18 @@ public static partial class AsyncSuperEnumerable /// A projection function which accepts the current and lagged items (in that order) and returns a result /// A sequence produced by projecting each element of the sequence with its lagged pairing - public static IAsyncEnumerable Lag(this IAsyncEnumerable source, int offset, Func resultSelector) + public static IAsyncEnumerable Lag( + this IAsyncEnumerable source, + int offset, + Func resultSelector + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(resultSelector); - return source.Select(Some) - .Lag(offset, default, (curr, lag) => resultSelector(curr.Value, lag is (true, var some) ? some : default)); + return source + .Select(Some) + .Lag(offset, default, (curr, lag) => resultSelector(curr.Value, lag is (true, var some) ? some : default)); } /// @@ -59,12 +65,22 @@ public static IAsyncEnumerable Lag(this IAsyncEnumera /// A projection function which accepts the current and lagged items (in that order) and returns a result /// A sequence produced by projecting each element of the sequence with its lagged pairing - public static IAsyncEnumerable Lag(this IAsyncEnumerable source, int offset, TSource defaultLagValue, Func resultSelector) + public static IAsyncEnumerable Lag( + this IAsyncEnumerable source, + int offset, + TSource defaultLagValue, + Func resultSelector + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(resultSelector); - return source.Lag(offset, defaultLagValue, (curr, lag) => new ValueTask(resultSelector(curr, lag))); + return source + .Lag( + offset, + defaultLagValue, + (curr, lag) => new ValueTask(resultSelector(curr, lag)) + ); } /// @@ -81,7 +97,12 @@ public static IAsyncEnumerable Lag(this IAsyncEnumera /// A projection function which accepts the current and lagged items (in that order) and returns a result /// A sequence produced by projecting each element of the sequence with its lagged pairing - public static IAsyncEnumerable Lag(this IAsyncEnumerable source, int offset, TSource defaultLagValue, Func> resultSelector) + public static IAsyncEnumerable Lag( + this IAsyncEnumerable source, + int offset, + TSource defaultLagValue, + Func> resultSelector + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(resultSelector); @@ -89,7 +110,13 @@ public static IAsyncEnumerable Lag(this IAsyncEnumera return Core(source, offset, defaultLagValue, resultSelector); - static async IAsyncEnumerable Core(IAsyncEnumerable source, int offset, TSource defaultLagValue, Func> resultSelector, [EnumeratorCancellation] CancellationToken cancellationToken = default) + static async IAsyncEnumerable Core( + IAsyncEnumerable source, + int offset, + TSource defaultLagValue, + Func> resultSelector, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { var lagQueue = new Queue(offset + 1); await foreach (var item in source.WithCancellation(cancellationToken).ConfigureAwait(false)) @@ -97,7 +124,8 @@ static async IAsyncEnumerable Core(IAsyncEnumerable source, in lagQueue.Enqueue(item); yield return await resultSelector( item, - lagQueue.Count > offset ? lagQueue.Dequeue() : defaultLagValue) + lagQueue.Count > offset ? lagQueue.Dequeue() : defaultLagValue + ) .ConfigureAwait(false); } } diff --git a/Source/SuperLinq.Async/LastIndexOf.cs b/Source/SuperLinq.Async/LastIndexOf.cs index 94db30bed..c314851f0 100644 --- a/Source/SuperLinq.Async/LastIndexOf.cs +++ b/Source/SuperLinq.Async/LastIndexOf.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -31,7 +31,11 @@ public static partial class AsyncSuperEnumerable /// This operator executes immediately. /// /// - public static ValueTask LastIndexOf(this IAsyncEnumerable source, TSource item, CancellationToken cancellationToken = default) + public static ValueTask LastIndexOf( + this IAsyncEnumerable source, + TSource item, + CancellationToken cancellationToken = default + ) { return source.LastIndexOf(item, ^1, int.MaxValue, cancellationToken); } @@ -69,7 +73,12 @@ public static ValueTask LastIndexOf(this IAsyncEnumerable /// This operator executes immediately. /// /// - public static ValueTask LastIndexOf(this IAsyncEnumerable source, TSource item, Index index, CancellationToken cancellationToken = default) + public static ValueTask LastIndexOf( + this IAsyncEnumerable source, + TSource item, + Index index, + CancellationToken cancellationToken = default + ) { return source.LastIndexOf(item, index, int.MaxValue, cancellationToken); } @@ -109,8 +118,20 @@ public static ValueTask LastIndexOf(this IAsyncEnumerable /// This operator executes immediately. /// /// - public static ValueTask LastIndexOf(this IAsyncEnumerable source, TSource item, Index index, int count, CancellationToken cancellationToken = default) + public static ValueTask LastIndexOf( + this IAsyncEnumerable source, + TSource item, + Index index, + int count, + CancellationToken cancellationToken = default + ) { - return FindLastIndex(source, i => EqualityComparer.Default.Equals(i, item), index, count, cancellationToken); + return FindLastIndex( + source, + i => EqualityComparer.Default.Equals(i, item), + index, + count, + cancellationToken + ); } } diff --git a/Source/SuperLinq.Async/Lead.cs b/Source/SuperLinq.Async/Lead.cs index 7f361a013..d4dacc396 100644 --- a/Source/SuperLinq.Async/Lead.cs +++ b/Source/SuperLinq.Async/Lead.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -18,8 +18,9 @@ public static partial class AsyncSuperEnumerable { ArgumentNullException.ThrowIfNull(source); - return source.Select(Some) - .Lead(offset, default, (curr, lead) => (curr.Value, lead is (true, var some) ? some : default)); + return source + .Select(Some) + .Lead(offset, default, (curr, lead) => (curr.Value, lead is (true, var some) ? some : default)); } /// @@ -37,13 +38,17 @@ public static partial class AsyncSuperEnumerable /// A projection function which accepts the current and subsequent (lead) element (in that order) and produces a result /// A sequence produced by projecting each element of the sequence with its lead pairing - public static IAsyncEnumerable Lead(this IAsyncEnumerable source, int offset, Func resultSelector) + public static IAsyncEnumerable Lead( + this IAsyncEnumerable source, + int offset, + Func resultSelector) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(resultSelector); - return source.Select(Some) - .Lead(offset, default, (curr, lead) => resultSelector(curr.Value, lead is (true, var some) ? some : default)); + return source + .Select(Some) + .Lead(offset, default, (curr, lead) => resultSelector(curr.Value, lead is (true, var some) ? some : default)); } /// @@ -60,7 +65,12 @@ public static IAsyncEnumerable Lead(this IAsyncEnumer /// A projection function which accepts the current and subsequent (lead) element (in that order) and produces a result /// A sequence produced by projecting each element of the sequence with its lead pairing - public static IAsyncEnumerable Lead(this IAsyncEnumerable source, int offset, TSource defaultLeadValue, Func resultSelector) + public static IAsyncEnumerable Lead( + this IAsyncEnumerable source, + int offset, + TSource defaultLeadValue, + Func resultSelector + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(resultSelector); @@ -82,7 +92,12 @@ public static IAsyncEnumerable Lead(this IAsyncEnumer /// A projection function which accepts the current and subsequent (lead) element (in that order) and produces a result /// A sequence produced by projecting each element of the sequence with its lead pairing - public static IAsyncEnumerable Lead(this IAsyncEnumerable source, int offset, TSource defaultLeadValue, Func> resultSelector) + public static IAsyncEnumerable Lead( + this IAsyncEnumerable source, + int offset, + TSource defaultLeadValue, + Func> resultSelector + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(resultSelector); @@ -90,7 +105,13 @@ public static IAsyncEnumerable Lead(this IAsyncEnumer return Core(source, offset, defaultLeadValue, resultSelector); - static async IAsyncEnumerable Core(IAsyncEnumerable source, int offset, TSource defaultLeadValue, Func> resultSelector, [EnumeratorCancellation] CancellationToken cancellationToken = default) + static async IAsyncEnumerable Core( + IAsyncEnumerable source, + int offset, + TSource defaultLeadValue, + Func> resultSelector, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { var queue = new Queue(offset + 1); diff --git a/Source/SuperLinq.Async/MaxItems.cs b/Source/SuperLinq.Async/MaxItems.cs index d5ba12443..aa9c68cba 100644 --- a/Source/SuperLinq.Async/MaxItems.cs +++ b/Source/SuperLinq.Async/MaxItems.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -11,7 +11,7 @@ public static partial class AsyncSuperEnumerable /// /// /// This operator is a shortcut for with a - /// direction of and a count of 1. + /// direction of and a count of 1. /// /// /// This operator uses deferred execution and streams it results. @@ -32,7 +32,7 @@ public static IAsyncEnumerable MaxItems(this IAsyncEnumerable source) /// /// /// This operator is a shortcut for with a - /// count of 1. + /// count of 1. /// /// /// This operator uses deferred execution and streams it results. @@ -55,13 +55,16 @@ public static IAsyncEnumerable MaxItems(this IAsyncEnumerable source, I /// /// This operator is a shortcut for with a direction of - /// and a count of 1. + /// and a count of 1. /// /// /// This operator uses deferred execution and streams it results. /// /// - public static IAsyncEnumerable MaxItemsBy(this IAsyncEnumerable source, Func keySelector) + public static IAsyncEnumerable MaxItemsBy( + this IAsyncEnumerable source, + Func keySelector + ) { return source.DensePartialSortBy(1, keySelector, OrderByDirection.Descending); } @@ -78,13 +81,16 @@ public static IAsyncEnumerable MaxItemsBy(this IAsyncEnu /// /// This operator is a shortcut for with a direction of - /// and a count of 1. + /// and a count of 1. /// /// /// This operator uses deferred execution and streams it results. /// /// - public static IAsyncEnumerable MaxByWithTies(this IAsyncEnumerable source, Func keySelector) + public static IAsyncEnumerable MaxByWithTies( + this IAsyncEnumerable source, + Func keySelector + ) { return source.DensePartialSortBy(1, keySelector, OrderByDirection.Descending); } @@ -102,13 +108,17 @@ public static IAsyncEnumerable MaxByWithTies(this IAsync /// /// This operator is a shortcut for with a direction of and a count of 1. + /// cref="OrderByDirection.Descending"/> and a count of 1. /// /// /// This operator uses deferred execution and streams it results. /// /// - public static IAsyncEnumerable MaxItemsBy(this IAsyncEnumerable source, Func keySelector, IComparer? comparer) + public static IAsyncEnumerable MaxItemsBy( + this IAsyncEnumerable source, + Func keySelector, + IComparer? comparer + ) { return source.DensePartialSortBy(1, keySelector, comparer, OrderByDirection.Descending); } @@ -126,13 +136,17 @@ public static IAsyncEnumerable MaxItemsBy(this IAsyncEnu /// /// This operator is a shortcut for with a direction of and a count of 1. + /// cref="OrderByDirection.Descending"/> and a count of 1. /// /// /// This operator uses deferred execution and streams it results. /// /// - public static IAsyncEnumerable MaxByWithTies(this IAsyncEnumerable source, Func keySelector, IComparer? comparer) + public static IAsyncEnumerable MaxByWithTies( + this IAsyncEnumerable source, + Func keySelector, + IComparer? comparer + ) { return source.DensePartialSortBy(1, keySelector, comparer, OrderByDirection.Descending); } diff --git a/Source/SuperLinq.Async/Memoize.cs b/Source/SuperLinq.Async/Memoize.cs index d75df1d39..2b04ba079 100644 --- a/Source/SuperLinq.Async/Memoize.cs +++ b/Source/SuperLinq.Async/Memoize.cs @@ -66,6 +66,7 @@ public async ValueTask Reset(CancellationToken cancellationToken = default) _initialized = false; if (_enumerator is not null) await _enumerator.DisposeAsync().ConfigureAwait(false); + _enumerator = null; _exceptionIndex = null; _exception = null; @@ -138,6 +139,7 @@ private async IAsyncEnumerator GetEnumeratorImpl(CancellationToken cancellati { if (_disposed) ThrowHelper.ThrowObjectDisposedException>(); + if (!_initialized || buffer != _buffer) { @@ -205,6 +207,7 @@ public async ValueTask DisposeAsync() _buffer.Clear(); if (_enumerator is not null) await _enumerator.DisposeAsync().ConfigureAwait(false); + _enumerator = null; _source = null; } diff --git a/Source/SuperLinq.Async/MinItems.cs b/Source/SuperLinq.Async/MinItems.cs index b51572b1b..da52bdfb8 100644 --- a/Source/SuperLinq.Async/MinItems.cs +++ b/Source/SuperLinq.Async/MinItems.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -11,7 +11,7 @@ public static partial class AsyncSuperEnumerable /// /// /// This operator is a shortcut for with a - /// direction of and a count of 1. + /// direction of and a count of 1. /// /// /// This operator uses deferred execution and streams it results. @@ -32,7 +32,7 @@ public static IAsyncEnumerable MinItems(this IAsyncEnumerable source) /// /// /// This operator is a shortcut for with a - /// count of 1. + /// count of 1. /// /// /// This operator uses deferred execution and streams it results. @@ -55,7 +55,7 @@ public static IAsyncEnumerable MinItems(this IAsyncEnumerable source, I /// /// This operator is a shortcut for with a direction of - /// and a count of 1. + /// and a count of 1. /// /// /// This operator uses deferred execution and streams it results. @@ -78,13 +78,16 @@ public static IAsyncEnumerable MinItemsBy(this IAsyncEnu /// /// This operator is a shortcut for with a direction of - /// and a count of 1. + /// and a count of 1. /// /// /// This operator uses deferred execution and streams it results. /// /// - public static IAsyncEnumerable MinByWithTies(this IAsyncEnumerable source, Func keySelector) + public static IAsyncEnumerable MinByWithTies( + this IAsyncEnumerable source, + Func keySelector + ) { return source.DensePartialSortBy(1, keySelector, OrderByDirection.Ascending); } @@ -102,13 +105,17 @@ public static IAsyncEnumerable MinByWithTies(this IAsync /// /// This operator is a shortcut for with a direction of and a count of 1. + /// cref="OrderByDirection.Ascending"/> and a count of 1. /// /// /// This operator uses deferred execution and streams it results. /// /// - public static IAsyncEnumerable MinItemsBy(this IAsyncEnumerable source, Func keySelector, IComparer? comparer) + public static IAsyncEnumerable MinItemsBy( + this IAsyncEnumerable source, + Func keySelector, + IComparer? comparer + ) { return source.DensePartialSortBy(1, keySelector, comparer, OrderByDirection.Ascending); } @@ -126,13 +133,17 @@ public static IAsyncEnumerable MinItemsBy(this IAsyncEnu /// /// This operator is a shortcut for with a direction of and a count of 1. + /// cref="OrderByDirection.Ascending"/> and a count of 1. /// /// /// This operator uses deferred execution and streams it results. /// /// - public static IAsyncEnumerable MinByWithTies(this IAsyncEnumerable source, Func keySelector, IComparer? comparer) + public static IAsyncEnumerable MinByWithTies( + this IAsyncEnumerable source, + Func keySelector, + IComparer? comparer + ) { return source.DensePartialSortBy(1, keySelector, comparer, OrderByDirection.Ascending); } diff --git a/Source/SuperLinq.Async/OnErrorResumeNext.cs b/Source/SuperLinq.Async/OnErrorResumeNext.cs index 5107d086f..e450cd3de 100644 --- a/Source/SuperLinq.Async/OnErrorResumeNext.cs +++ b/Source/SuperLinq.Async/OnErrorResumeNext.cs @@ -16,7 +16,7 @@ public static IAsyncEnumerable OnErrorResumeNext(this IAsyncEn ArgumentNullException.ThrowIfNull(first); ArgumentNullException.ThrowIfNull(second); - return OnErrorResumeNext(new[] { first, second, }); + return OnErrorResumeNext(new[] { first, second }); } /// diff --git a/Source/SuperLinq.Async/OrderBy.cs b/Source/SuperLinq.Async/OrderBy.cs index 13beab9fb..30d23be6f 100644 --- a/Source/SuperLinq.Async/OrderBy.cs +++ b/Source/SuperLinq.Async/OrderBy.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -12,10 +12,15 @@ public static partial class AsyncSuperEnumerable /// A direction in which to order the elements (ascending, descending) /// An ordered copy of the source sequence - public static IOrderedAsyncEnumerable OrderBy(this IAsyncEnumerable source, Func keySelector, OrderByDirection direction) + public static IOrderedAsyncEnumerable OrderBy( + this IAsyncEnumerable source, + Func keySelector, + OrderByDirection direction + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(keySelector); + return direction == OrderByDirection.Ascending ? source.OrderBy(keySelector) : source.OrderByDescending(keySelector); @@ -28,14 +33,20 @@ public static IOrderedAsyncEnumerable OrderBy(this IAsyncEnumerable< /// The type of the key used to order elements /// The sequence to order /// A key selector function - /// A direction in which to order the elements (ascending, descending) /// A comparer used to define the semantics of element comparison + /// A direction in which to order the elements (ascending, descending) /// An ordered copy of the source sequence - public static IOrderedAsyncEnumerable OrderBy(this IAsyncEnumerable source, Func keySelector, IComparer comparer, OrderByDirection direction) + public static IOrderedAsyncEnumerable OrderBy( + this IAsyncEnumerable source, + Func keySelector, + IComparer comparer, + OrderByDirection direction + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(keySelector); + return direction == OrderByDirection.Ascending ? source.OrderBy(keySelector, comparer) : source.OrderByDescending(keySelector, comparer); @@ -51,10 +62,15 @@ public static IOrderedAsyncEnumerable OrderBy(this IAsyncEnumerable< /// A direction in which to order the elements (ascending, descending) /// An ordered copy of the source sequence - public static IOrderedAsyncEnumerable ThenBy(this IOrderedAsyncEnumerable source, Func keySelector, OrderByDirection direction) + public static IOrderedAsyncEnumerable ThenBy( + this IOrderedAsyncEnumerable source, + Func keySelector, + OrderByDirection direction + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(keySelector); + return direction == OrderByDirection.Ascending ? source.ThenBy(keySelector) : source.ThenByDescending(keySelector); @@ -67,14 +83,20 @@ public static IOrderedAsyncEnumerable ThenBy(this IOrderedAsyncEnume /// The type of the key used to order elements /// The sequence to order /// A key selector function - /// A direction in which to order the elements (ascending, descending) /// A comparer used to define the semantics of element comparison + /// A direction in which to order the elements (ascending, descending) /// An ordered copy of the source sequence - public static IOrderedAsyncEnumerable ThenBy(this IOrderedAsyncEnumerable source, Func keySelector, IComparer comparer, OrderByDirection direction) + public static IOrderedAsyncEnumerable ThenBy( + this IOrderedAsyncEnumerable source, + Func keySelector, + IComparer comparer, + OrderByDirection direction + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(keySelector); + return direction == OrderByDirection.Ascending ? source.ThenBy(keySelector, comparer) : source.ThenByDescending(keySelector, comparer); diff --git a/Source/SuperLinq.Async/PadStart.cs b/Source/SuperLinq.Async/PadStart.cs index b93c4b0c7..5e3aaba09 100644 --- a/Source/SuperLinq.Async/PadStart.cs +++ b/Source/SuperLinq.Async/PadStart.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -88,7 +88,11 @@ public static IAsyncEnumerable PadStart(this IAsyncEnumerable< /// is . /// is . /// is less than 0. - public static IAsyncEnumerable PadStart(this IAsyncEnumerable source, int width, Func paddingSelector) + public static IAsyncEnumerable PadStart( + this IAsyncEnumerable source, + int width, + Func paddingSelector + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(paddingSelector); @@ -99,7 +103,8 @@ public static IAsyncEnumerable PadStart(this IAsyncEnumerable< static async IAsyncEnumerable PadStartImpl( IAsyncEnumerable source, int width, Func paddingSelector, - [EnumeratorCancellation] CancellationToken cancellationToken = default) + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { var array = new TSource[width]; var count = 0; diff --git a/Source/SuperLinq.Async/PartialSort.cs b/Source/SuperLinq.Async/PartialSort.cs index 673375cc0..3433417b2 100644 --- a/Source/SuperLinq.Async/PartialSort.cs +++ b/Source/SuperLinq.Async/PartialSort.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -22,7 +22,10 @@ public static partial class AsyncSuperEnumerable /// This operator uses deferred execution and streams it results. /// /// - public static IAsyncEnumerable PartialSort(this IAsyncEnumerable source, int count) + public static IAsyncEnumerable PartialSort( + this IAsyncEnumerable source, + int count + ) { return source.PartialSort(count, comparer: null); } @@ -49,7 +52,10 @@ public static IAsyncEnumerable PartialSort(this IAsyncEnumerable source /// /// public static IAsyncEnumerable PartialSort( - this IAsyncEnumerable source, int count, OrderByDirection direction) + this IAsyncEnumerable source, + int count, + OrderByDirection direction + ) { return source.PartialSort(count, comparer: null, direction); } @@ -77,7 +83,9 @@ public static IAsyncEnumerable PartialSort( /// public static IAsyncEnumerable PartialSort( this IAsyncEnumerable source, - int count, IComparer? comparer) + int count, + IComparer? comparer + ) { return PartialSort(source, count, comparer, OrderByDirection.Ascending); } @@ -105,8 +113,11 @@ public static IAsyncEnumerable PartialSort( /// /// public static IAsyncEnumerable PartialSort( - this IAsyncEnumerable source, int count, - IComparer? comparer, OrderByDirection direction) + this IAsyncEnumerable source, + int count, + IComparer? comparer, + OrderByDirection direction + ) { ArgumentNullException.ThrowIfNull(source); ArgumentOutOfRangeException.ThrowIfNegativeOrZero(count); @@ -117,7 +128,12 @@ public static IAsyncEnumerable PartialSort( return Core(source, count, comparer); - static async IAsyncEnumerable Core(IAsyncEnumerable source, int count, IComparer comparer, [EnumeratorCancellation] CancellationToken cancellationToken = default) + static async IAsyncEnumerable Core( + IAsyncEnumerable source, + int count, + IComparer comparer, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { var top = new SortedSet<(T item, int index)>( ValueTupleComparer.Create(comparer, default)); @@ -153,8 +169,8 @@ static async IAsyncEnumerable Core(IAsyncEnumerable source, int count, ICo /// Type of elements in the sequence. /// Type of keys. /// The source sequence. - /// A function to extract a key from an element. /// Number of (maximum) elements to return. + /// A function to extract a key from an element. /// A sequence containing at most top elements from source, in ascending order of /// their keys. /// is . @@ -183,8 +199,8 @@ public static IAsyncEnumerable PartialSortBy( /// Type of elements in the sequence. /// Type of keys. /// The source sequence. - /// A function to extract a key from an element. /// Number of (maximum) elements to return. + /// A function to extract a key from an element. /// The direction in which to sort the elements /// A sequence containing at most top elements from source, in the specified order /// of their keys. @@ -200,8 +216,11 @@ public static IAsyncEnumerable PartialSortBy( /// /// public static IAsyncEnumerable PartialSortBy( - this IAsyncEnumerable source, int count, - Func keySelector, OrderByDirection direction) + this IAsyncEnumerable source, + int count, + Func keySelector, + OrderByDirection direction + ) { return source.PartialSortBy(count, keySelector, comparer: null, direction); } @@ -214,8 +233,8 @@ public static IAsyncEnumerable PartialSortBy( /// Type of elements in the sequence. /// Type of keys. /// The source sequence. - /// A function to extract a key from an element. /// Number of (maximum) elements to return. + /// A function to extract a key from an element. /// A to compare elements. /// A sequence containing at most top elements from source, in ascending order of /// their keys. @@ -231,9 +250,11 @@ public static IAsyncEnumerable PartialSortBy( /// /// public static IAsyncEnumerable PartialSortBy( - this IAsyncEnumerable source, int count, + this IAsyncEnumerable source, + int count, Func keySelector, - IComparer? comparer) + IComparer? comparer + ) { return PartialSortBy(source, count, keySelector, comparer, OrderByDirection.Ascending); } @@ -247,8 +268,8 @@ public static IAsyncEnumerable PartialSortBy( /// Type of elements in the sequence. /// Type of keys. /// The source sequence. - /// A function to extract a key from an element. /// Number of (maximum) elements to return. + /// A function to extract a key from an element. /// A to compare elements. /// The direction in which to sort the elements /// A sequence containing at most top elements from source, in the specified order @@ -268,7 +289,8 @@ public static IAsyncEnumerable PartialSortBy( this IAsyncEnumerable source, int count, Func keySelector, IComparer? comparer, - OrderByDirection direction) + OrderByDirection direction + ) { ArgumentNullException.ThrowIfNull(source); ArgumentOutOfRangeException.ThrowIfNegativeOrZero(count); @@ -280,10 +302,17 @@ public static IAsyncEnumerable PartialSortBy( return Core(source, count, keySelector, comparer); - static async IAsyncEnumerable Core(IAsyncEnumerable source, int count, Func keySelector, IComparer comparer, [EnumeratorCancellation] CancellationToken cancellationToken = default) + static async IAsyncEnumerable Core( + IAsyncEnumerable source, + int count, + Func keySelector, + IComparer comparer, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { var top = new SortedSet<(TKey Key, int Index)>( ValueTupleComparer.Create(comparer, default)); + var dic = new Dictionary<(TKey Key, int Index), TSource>(count); var index = 0; diff --git a/Source/SuperLinq.Async/Publish.cs b/Source/SuperLinq.Async/Publish.cs index 8fc999e9e..3cce3cd30 100644 --- a/Source/SuperLinq.Async/Publish.cs +++ b/Source/SuperLinq.Async/Publish.cs @@ -1,4 +1,4 @@ -using System.Runtime.ExceptionServices; +using System.Runtime.ExceptionServices; namespace SuperLinq.Async; @@ -60,6 +60,7 @@ public async ValueTask Reset(CancellationToken cancellationToken = default) if (_enumerator is not null) await _enumerator.DisposeAsync(); + _enumerator = null; _exception = null; _exceptionOnGetEnumerator = null; @@ -139,6 +140,7 @@ private async IAsyncEnumerator GetEnumeratorImpl(Queue buffer, int version { if (_disposed) ThrowHelper.ThrowObjectDisposedException>(); + if (!_initialized || version != _version) { @@ -218,6 +220,7 @@ public async ValueTask DisposeAsync() if (_enumerator is not null) await _enumerator.DisposeAsync().ConfigureAwait(false); + _enumerator = null; _source = null; } diff --git a/Source/SuperLinq.Async/Random.cs b/Source/SuperLinq.Async/Random.cs index e84bbbb45..5138dd107 100644 --- a/Source/SuperLinq.Async/Random.cs +++ b/Source/SuperLinq.Async/Random.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -185,7 +185,11 @@ public static IAsyncEnumerable RandomDouble(Random rand) /// /// An infinite sequence of random numbers of type T #pragma warning disable CS1998 - private static async IAsyncEnumerable RandomImpl(Random rand, Func nextValue, [EnumeratorCancellation] CancellationToken cancellationToken = default) + private static async IAsyncEnumerable RandomImpl( + Random rand, + Func nextValue, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { while (true) { diff --git a/Source/SuperLinq.Async/Repeat.cs b/Source/SuperLinq.Async/Repeat.cs index 4db5b5872..41da1f84c 100644 --- a/Source/SuperLinq.Async/Repeat.cs +++ b/Source/SuperLinq.Async/Repeat.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public partial class AsyncSuperEnumerable { @@ -35,9 +35,11 @@ static async IAsyncEnumerable Core( await using var buffer = source.Memoize(); while (true) { - await foreach (var el in buffer + await foreach (var el in + buffer .WithCancellation(cancellationToken) - .ConfigureAwait(false)) + .ConfigureAwait(false) + ) { yield return el; } @@ -71,9 +73,11 @@ static async IAsyncEnumerable Core( await using var buffer = source.Memoize(); while (count-- > 0) { - await foreach (var el in buffer + await foreach (var el in + buffer .WithCancellation(cancellationToken) - .ConfigureAwait(false)) + .ConfigureAwait(false) + ) { yield return el; } diff --git a/Source/SuperLinq.Async/RunLengthEncode.cs b/Source/SuperLinq.Async/RunLengthEncode.cs index 4b5d4ba08..fb0973161 100644 --- a/Source/SuperLinq.Async/RunLengthEncode.cs +++ b/Source/SuperLinq.Async/RunLengthEncode.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -31,7 +31,11 @@ public static partial class AsyncSuperEnumerable return Core(sequence, comparer ?? EqualityComparer.Default); - static async IAsyncEnumerable<(T value, int count)> Core(IAsyncEnumerable sequence, IEqualityComparer comparer, [EnumeratorCancellation] CancellationToken cancellationToken = default) + static async IAsyncEnumerable<(T value, int count)> Core( + IAsyncEnumerable sequence, + IEqualityComparer comparer, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { // This implementation could also have been written using a foreach loop, // but it proved to be easier to deal with edge certain cases that occur diff --git a/Source/SuperLinq.Async/ScanRight.cs b/Source/SuperLinq.Async/ScanRight.cs index ffe4e3cf6..d52213c1e 100644 --- a/Source/SuperLinq.Async/ScanRight.cs +++ b/Source/SuperLinq.Async/ScanRight.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -57,7 +57,10 @@ public static IAsyncEnumerable ScanRight(this IAsyncEnumerable /// This operator uses deferred execution and streams its results. /// Source sequence is consumed greedily when an iteration of the resulting sequence begins. /// - public static IAsyncEnumerable ScanRight(this IAsyncEnumerable source, Func> func) + public static IAsyncEnumerable ScanRight( + this IAsyncEnumerable source, + Func> func + ) { ArgumentNullException.ThrowIfNull(func); @@ -88,14 +91,21 @@ public static IAsyncEnumerable ScanRight(this IAsyncEnumerable /// This operator uses deferred execution and streams its results. /// Source sequence is consumed greedily when an iteration of the resulting sequence begins. /// - public static IAsyncEnumerable ScanRight(this IAsyncEnumerable source, Func> func) + public static IAsyncEnumerable ScanRight( + this IAsyncEnumerable source, + Func> func + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(func); return Core(source, func); - static async IAsyncEnumerable Core(IAsyncEnumerable source, Func> func, [EnumeratorCancellation] CancellationToken cancellationToken = default) + static async IAsyncEnumerable Core( + IAsyncEnumerable source, + Func> func, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { var list = await source.ToListAsync(cancellationToken).ConfigureAwait(false); @@ -142,7 +152,11 @@ static async IAsyncEnumerable Core(IAsyncEnumerable source, Fu /// This operator uses deferred execution and streams its results. /// Source sequence is consumed greedily when an iteration of the resulting sequence begins. /// - public static IAsyncEnumerable ScanRight(this IAsyncEnumerable source, TAccumulate seed, Func func) + public static IAsyncEnumerable ScanRight( + this IAsyncEnumerable source, + TAccumulate seed, + Func func + ) { ArgumentNullException.ThrowIfNull(func); @@ -174,7 +188,11 @@ public static IAsyncEnumerable ScanRight(this /// This operator uses deferred execution and streams its results. /// Source sequence is consumed greedily when an iteration of the resulting sequence begins. /// - public static IAsyncEnumerable ScanRight(this IAsyncEnumerable source, TAccumulate seed, Func> func) + public static IAsyncEnumerable ScanRight( + this IAsyncEnumerable source, + TAccumulate seed, + Func> func + ) { ArgumentNullException.ThrowIfNull(func); @@ -206,14 +224,22 @@ public static IAsyncEnumerable ScanRight(this /// This operator uses deferred execution and streams its results. /// Source sequence is consumed greedily when an iteration of the resulting sequence begins. /// - public static IAsyncEnumerable ScanRight(this IAsyncEnumerable source, TAccumulate seed, Func> func) + public static IAsyncEnumerable ScanRight( + this IAsyncEnumerable source, + TAccumulate seed, + Func> func + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(func); return Core(source, seed, func); - static async IAsyncEnumerable Core(IAsyncEnumerable source, TAccumulate seed, Func> func, [EnumeratorCancellation] CancellationToken cancellationToken = default) + static async IAsyncEnumerable Core( + IAsyncEnumerable source, + TAccumulate seed, + Func> func, + [EnumeratorCancellation] CancellationToken cancellationToken = default) { var list = await source.ToListAsync(cancellationToken).ConfigureAwait(false); diff --git a/Source/SuperLinq.Async/Segment.cs b/Source/SuperLinq.Async/Segment.cs index 42eb87f2f..1c20222f0 100644 --- a/Source/SuperLinq.Async/Segment.cs +++ b/Source/SuperLinq.Async/Segment.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -51,7 +51,10 @@ public static IAsyncEnumerable> Segment(this IAsyncEnumerabl /// Thrown if either or are . /// - public static IAsyncEnumerable> Segment(this IAsyncEnumerable source, Func newSegmentPredicate) + public static IAsyncEnumerable> Segment( + this IAsyncEnumerable source, + Func newSegmentPredicate + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(newSegmentPredicate); @@ -70,7 +73,10 @@ public static IAsyncEnumerable> Segment(this IAsyncEnumerabl /// Thrown if either or are . /// - public static IAsyncEnumerable> Segment(this IAsyncEnumerable source, Func> newSegmentPredicate) + public static IAsyncEnumerable> Segment( + this IAsyncEnumerable source, + Func> newSegmentPredicate + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(newSegmentPredicate); @@ -89,7 +95,10 @@ public static IAsyncEnumerable> Segment(this IAsyncEnumerabl /// Thrown if either or are . /// - public static IAsyncEnumerable> Segment(this IAsyncEnumerable source, Func newSegmentPredicate) + public static IAsyncEnumerable> Segment( + this IAsyncEnumerable source, + Func newSegmentPredicate + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(newSegmentPredicate); @@ -108,14 +117,21 @@ public static IAsyncEnumerable> Segment(this IAsyncEnumerabl /// Thrown if either or are . /// - public static IAsyncEnumerable> Segment(this IAsyncEnumerable source, Func> newSegmentPredicate) + public static IAsyncEnumerable> Segment( + this IAsyncEnumerable source, + Func> newSegmentPredicate + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(newSegmentPredicate); return Core(source, newSegmentPredicate); - static async IAsyncEnumerable> Core(IAsyncEnumerable source, Func> newSegmentPredicate, [EnumeratorCancellation] CancellationToken cancellationToken = default) + static async IAsyncEnumerable> Core( + IAsyncEnumerable source, + Func> newSegmentPredicate, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { await using var e = source.GetConfiguredAsyncEnumerator(cancellationToken); @@ -135,7 +151,7 @@ static async IAsyncEnumerable> Core(IAsyncEnumerable source, if (await newSegmentPredicate(current, previous, index).ConfigureAwait(false)) { - yield return segment; // yield the completed segment + yield return segment; // yield the completed segment segment = [current]; // start a new segment } else // not a new segment, append and continue diff --git a/Source/SuperLinq.Async/Share.cs b/Source/SuperLinq.Async/Share.cs index cea54d4c6..55f795071 100644 --- a/Source/SuperLinq.Async/Share.cs +++ b/Source/SuperLinq.Async/Share.cs @@ -53,6 +53,7 @@ public async ValueTask Reset(CancellationToken cancellationToken = default) if (_enumerator is not null) await _enumerator.DisposeAsync(); + _enumerator = null; _exception = null; } @@ -118,6 +119,7 @@ private async IAsyncEnumerator GetEnumeratorImpl(CancellationToken cancellati { if (_disposed) ThrowHelper.ThrowObjectDisposedException>(); + if (!_initialized || version != _version) { @@ -171,6 +173,7 @@ public async ValueTask DisposeAsync() _disposed = true; if (_enumerator is not null) await _enumerator.DisposeAsync().ConfigureAwait(false); + _enumerator = null; _source = null; } diff --git a/Source/SuperLinq.Async/SkipUntil.cs b/Source/SuperLinq.Async/SkipUntil.cs index f7db352a4..45a5bbf63 100644 --- a/Source/SuperLinq.Async/SkipUntil.cs +++ b/Source/SuperLinq.Async/SkipUntil.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -39,7 +39,11 @@ public static IAsyncEnumerable SkipUntil(this IAsyncEnumerable return Core(source, predicate); - static async IAsyncEnumerable Core(IAsyncEnumerable source, Func predicate, [EnumeratorCancellation] CancellationToken cancellationToken = default) + static async IAsyncEnumerable Core( + IAsyncEnumerable source, + Func predicate, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { await using var enumerator = source.GetConfiguredAsyncEnumerator(cancellationToken); diff --git a/Source/SuperLinq.Async/SortedMerge.cs b/Source/SuperLinq.Async/SortedMerge.cs index 694cd5ec0..8c7407dca 100644 --- a/Source/SuperLinq.Async/SortedMerge.cs +++ b/Source/SuperLinq.Async/SortedMerge.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -28,7 +28,10 @@ public static partial class AsyncSuperEnumerable /// A merged, order-preserving sequence containing all of the elements of the original sequences /// is . /// is . - public static IAsyncEnumerable SortedMerge(this IAsyncEnumerable source, params IAsyncEnumerable[] otherSequences) + public static IAsyncEnumerable SortedMerge( + this IAsyncEnumerable source, + params IAsyncEnumerable[] otherSequences + ) { return SortedMerge(source, OrderByDirection.Ascending, comparer: null, otherSequences); } @@ -60,7 +63,11 @@ public static IAsyncEnumerable SortedMerge(this IAsyncEnumerab /// A merged, order-preserving sequence containing all of the elements of the original sequences /// is . /// is . - public static IAsyncEnumerable SortedMerge(this IAsyncEnumerable source, IComparer? comparer, params IAsyncEnumerable[] otherSequences) + public static IAsyncEnumerable SortedMerge( + this IAsyncEnumerable source, + IComparer? comparer, + params IAsyncEnumerable[] otherSequences + ) { return SortedMerge(source, OrderByDirection.Ascending, comparer, otherSequences); } @@ -92,7 +99,11 @@ public static IAsyncEnumerable SortedMerge(this IAsyncEnumerab /// A merged, order-preserving sequence containing all of the elements of the original sequences /// is . /// is . - public static IAsyncEnumerable SortedMerge(this IAsyncEnumerable source, OrderByDirection direction, params IAsyncEnumerable[] otherSequences) + public static IAsyncEnumerable SortedMerge( + this IAsyncEnumerable source, + OrderByDirection direction, + params IAsyncEnumerable[] otherSequences + ) { return SortedMerge(source, direction, comparer: null, otherSequences); } @@ -125,7 +136,12 @@ public static IAsyncEnumerable SortedMerge(this IAsyncEnumerab /// A merged, order-preserving sequence containing all of the elements of the original sequences /// is . /// is . - public static IAsyncEnumerable SortedMerge(this IAsyncEnumerable source, OrderByDirection direction, IComparer? comparer, params IAsyncEnumerable[] otherSequences) + public static IAsyncEnumerable SortedMerge( + this IAsyncEnumerable source, + OrderByDirection direction, + IComparer? comparer, + params IAsyncEnumerable[] otherSequences + ) { return SortedMergeBy(source, Identity, direction, comparer, otherSequences); } @@ -148,7 +164,11 @@ public static IAsyncEnumerable SortedMerge(this IAsyncEnumerab /// is . /// is . /// is . - public static IAsyncEnumerable SortedMergeBy(this IAsyncEnumerable source, Func keySelector, params IAsyncEnumerable[] otherSequences) + public static IAsyncEnumerable SortedMergeBy( + this IAsyncEnumerable source, + Func keySelector, + params IAsyncEnumerable[] otherSequences + ) { return SortedMergeBy(source, keySelector, OrderByDirection.Ascending, comparer: null, otherSequences); } @@ -172,7 +192,12 @@ public static IAsyncEnumerable SortedMergeBy(this IAsync /// is . /// is . /// is . - public static IAsyncEnumerable SortedMergeBy(this IAsyncEnumerable source, Func keySelector, IComparer? comparer, params IAsyncEnumerable[] otherSequences) + public static IAsyncEnumerable SortedMergeBy( + this IAsyncEnumerable source, + Func keySelector, + IComparer? comparer, + params IAsyncEnumerable[] otherSequences + ) { return SortedMergeBy(source, keySelector, OrderByDirection.Ascending, comparer, otherSequences); } @@ -196,7 +221,12 @@ public static IAsyncEnumerable SortedMergeBy(this IAsync /// is . /// is . /// is . - public static IAsyncEnumerable SortedMergeBy(this IAsyncEnumerable source, Func keySelector, OrderByDirection direction, params IAsyncEnumerable[] otherSequences) + public static IAsyncEnumerable SortedMergeBy( + this IAsyncEnumerable source, + Func keySelector, + OrderByDirection direction, + params IAsyncEnumerable[] otherSequences + ) { return SortedMergeBy(source, keySelector, direction, comparer: null, otherSequences); } @@ -221,7 +251,13 @@ public static IAsyncEnumerable SortedMergeBy(this IAsync /// is . /// is . /// is . - public static IAsyncEnumerable SortedMergeBy(this IAsyncEnumerable source, Func keySelector, OrderByDirection direction, IComparer? comparer, params IAsyncEnumerable[] otherSequences) + public static IAsyncEnumerable SortedMergeBy( + this IAsyncEnumerable source, + Func keySelector, + OrderByDirection direction, + IComparer? comparer, + params IAsyncEnumerable[] otherSequences + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(keySelector); @@ -248,7 +284,12 @@ public static IAsyncEnumerable SortedMergeBy(this IAsync // // The algorithm used here will perform N*(K1+K2+...Kn-1) comparisons, where N => otherSequences.Count()+1. - static async IAsyncEnumerable Impl(IEnumerable> sequences, Func keySelector, IComparer comparer, [EnumeratorCancellation] CancellationToken cancellationToken = default) + static async IAsyncEnumerable Impl( + IEnumerable> sequences, + Func keySelector, + IComparer comparer, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { var list = await EnumeratorList.Create(sequences, cancellationToken).ConfigureAwait(false); await using var ignored_ = list.ConfigureAwait(false); diff --git a/Source/SuperLinq.Async/StartsWith.cs b/Source/SuperLinq.Async/StartsWith.cs index dfd43e588..d581d79cc 100644 --- a/Source/SuperLinq.Async/StartsWith.cs +++ b/Source/SuperLinq.Async/StartsWith.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -22,8 +22,11 @@ public static partial class AsyncSuperEnumerable /// on pairs of elements at /// the same index. /// - - public static ValueTask StartsWith(this IAsyncEnumerable first, IEnumerable second, CancellationToken cancellationToken = default) + public static ValueTask StartsWith( + this IAsyncEnumerable first, + IEnumerable second, + CancellationToken cancellationToken = default + ) { ArgumentNullException.ThrowIfNull(first); ArgumentNullException.ThrowIfNull(second); @@ -51,8 +54,11 @@ public static ValueTask StartsWith(this IAsyncEnumerable first, IEnu /// on pairs of elements at /// the same index. /// - - public static ValueTask StartsWith(this IAsyncEnumerable first, IAsyncEnumerable second, CancellationToken cancellationToken = default) + public static ValueTask StartsWith( + this IAsyncEnumerable first, + IAsyncEnumerable second, + CancellationToken cancellationToken = default + ) { return StartsWith(first, second, comparer: null, cancellationToken); } @@ -77,8 +83,12 @@ public static ValueTask StartsWith(this IAsyncEnumerable first, IAsy /// it calls on pairs /// of elements at the same index. /// - - public static ValueTask StartsWith(this IAsyncEnumerable first, IEnumerable second, IEqualityComparer? comparer, CancellationToken cancellationToken = default) + public static ValueTask StartsWith( + this IAsyncEnumerable first, + IEnumerable second, + IEqualityComparer? comparer, + CancellationToken cancellationToken = default + ) { ArgumentNullException.ThrowIfNull(first); ArgumentNullException.ThrowIfNull(second); @@ -106,8 +116,12 @@ public static ValueTask StartsWith(this IAsyncEnumerable first, IEnu /// it calls on pairs /// of elements at the same index. /// - - public static ValueTask StartsWith(this IAsyncEnumerable first, IAsyncEnumerable second, IEqualityComparer? comparer, CancellationToken cancellationToken = default) + public static ValueTask StartsWith( + this IAsyncEnumerable first, + IAsyncEnumerable second, + IEqualityComparer? comparer, + CancellationToken cancellationToken = default + ) { ArgumentNullException.ThrowIfNull(first); ArgumentNullException.ThrowIfNull(second); @@ -116,14 +130,20 @@ public static ValueTask StartsWith(this IAsyncEnumerable first, IAsy return Core(first, second, comparer, cancellationToken); - static async ValueTask Core(IAsyncEnumerable first, IAsyncEnumerable second, IEqualityComparer? comparer, CancellationToken cancellationToken) + static async ValueTask Core( + IAsyncEnumerable first, + IAsyncEnumerable second, + IEqualityComparer? comparer, + CancellationToken cancellationToken + ) { var snd = await second.ToListAsync(cancellationToken).ConfigureAwait(false); return await first.Take(snd.Count) .SequenceEqualAsync( snd.ToAsyncEnumerable(), comparer, - cancellationToken) + cancellationToken + ) .ConfigureAwait(false); } } diff --git a/Source/SuperLinq.Async/TagFirstLast.cs b/Source/SuperLinq.Async/TagFirstLast.cs index 29a4d51fa..692842980 100644 --- a/Source/SuperLinq.Async/TagFirstLast.cs +++ b/Source/SuperLinq.Async/TagFirstLast.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -61,14 +61,21 @@ public static partial class AsyncSuperEnumerable /// { Number = 456, IsFirst = False, IsLast = False } and /// { Number = 789, IsFirst = False, IsLast = True } in turn. /// - public static IAsyncEnumerable TagFirstLast(this IAsyncEnumerable source, Func resultSelector) + public static IAsyncEnumerable TagFirstLast( + this IAsyncEnumerable source, + Func resultSelector + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(resultSelector); return Core(source, resultSelector); - static async IAsyncEnumerable Core(IAsyncEnumerable source, Func resultSelector, [EnumeratorCancellation] CancellationToken cancellationToken = default) + static async IAsyncEnumerable Core( + IAsyncEnumerable source, + Func resultSelector, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { await using var iter = source.GetConfiguredAsyncEnumerator(cancellationToken); diff --git a/Source/SuperLinq.Async/Take.cs b/Source/SuperLinq.Async/Take.cs index 118ac0ca9..be0e9aa1b 100644 --- a/Source/SuperLinq.Async/Take.cs +++ b/Source/SuperLinq.Async/Take.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -22,9 +22,7 @@ public static IAsyncEnumerable Take(this IAsyncEnumerable= start.Value)) - { return AsyncEnumerable.Empty(); - } } else if (!end.IsFromEnd) { @@ -36,20 +34,21 @@ public static IAsyncEnumerable Take(this IAsyncEnumerable TakeRangeIterator(IAsyncEnumerable source, int startIndex, int endIndex, [EnumeratorCancellation] CancellationToken cancellationToken = default) + private static async IAsyncEnumerable TakeRangeIterator( + IAsyncEnumerable source, + int startIndex, + int endIndex, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { await using var e = source.GetConfiguredAsyncEnumerator(cancellationToken); var index = 0; while (index < startIndex && await e.MoveNextAsync()) - { ++index; - } if (index < startIndex) - { yield break; - } while (index < endIndex && await e.MoveNextAsync()) { @@ -58,7 +57,12 @@ private static async IAsyncEnumerable TakeRangeIterator(IAsync } } - private static async IAsyncEnumerable TakeRangeFromEndIterator(IAsyncEnumerable source, Index start, Index end, [EnumeratorCancellation] CancellationToken cancellationToken = default) + private static async IAsyncEnumerable TakeRangeFromEndIterator( + IAsyncEnumerable source, + Index start, + Index end, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { Queue queue; var count = 0; @@ -69,9 +73,7 @@ private static async IAsyncEnumerable TakeRangeFromEndIterator await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken)) { if (!await e.MoveNextAsync()) - { yield break; - } queue = new Queue(); queue.Enqueue(e.Current); @@ -84,7 +86,10 @@ private static async IAsyncEnumerable TakeRangeFromEndIterator _ = queue.Dequeue(); queue.Enqueue(e.Current); - checked { ++count; } + checked + { + ++count; + } } } @@ -92,9 +97,7 @@ private static async IAsyncEnumerable TakeRangeFromEndIterator var endIndex = Math.Min(count, end.GetOffset(count)); for (var rangeIndex = startIndex; rangeIndex < endIndex; rangeIndex++) - { yield return queue.Dequeue(); - } } else { @@ -104,9 +107,7 @@ private static async IAsyncEnumerable TakeRangeFromEndIterator var startCount = start.Value; var endCount = end.Value; while (count < startCount && await e.MoveNextAsync()) - { ++count; - } if (count == startCount) { diff --git a/Source/SuperLinq.Async/TakeUntil.cs b/Source/SuperLinq.Async/TakeUntil.cs index d5dd302af..d777e6d0e 100644 --- a/Source/SuperLinq.Async/TakeUntil.cs +++ b/Source/SuperLinq.Async/TakeUntil.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -39,7 +39,11 @@ public static IAsyncEnumerable TakeUntil(this IAsyncEnumerable return Core(source, predicate); - static async IAsyncEnumerable Core(IAsyncEnumerable source, Func predicate, [EnumeratorCancellation] CancellationToken cancellationToken = default) + static async IAsyncEnumerable Core( + IAsyncEnumerable source, + Func predicate, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { await foreach (var item in source.WithCancellation(cancellationToken).ConfigureAwait(false)) { diff --git a/Source/SuperLinq.Async/Throw.cs b/Source/SuperLinq.Async/Throw.cs index f7934c790..bb6cb08ff 100644 --- a/Source/SuperLinq.Async/Throw.cs +++ b/Source/SuperLinq.Async/Throw.cs @@ -11,7 +11,7 @@ public static partial class AsyncSuperEnumerable /// is . /// /// - /// The provided value () will be thrown when the first element is enumerated. + /// The provided value () will be thrown when the first element is enumerated. /// /// /// If the returned is enumerated multiple times, the same value will be thrown each diff --git a/Source/SuperLinq.Async/Traverse.cs b/Source/SuperLinq.Async/Traverse.cs index c16507f12..b49c7b1bc 100644 --- a/Source/SuperLinq.Async/Traverse.cs +++ b/Source/SuperLinq.Async/Traverse.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public partial class AsyncSuperEnumerable { @@ -92,10 +92,12 @@ static async IAsyncEnumerable Core( yield return current; // because a stack pops the elements out in LIFO order, we need to push them in reverse // if we want to traverse the returned list in the same order as was returned to us - await foreach (var child in childrenSelector(current) + await foreach (var child in + childrenSelector(current) .Reverse() .WithCancellation(cancellationToken) - .ConfigureAwait(false)) + .ConfigureAwait(false) + ) { stack.Push(child); } diff --git a/Source/SuperLinq.Async/Using.cs b/Source/SuperLinq.Async/Using.cs index add39f68a..b2c47cbeb 100644 --- a/Source/SuperLinq.Async/Using.cs +++ b/Source/SuperLinq.Async/Using.cs @@ -17,7 +17,7 @@ public static partial class AsyncSuperEnumerable /// /// and are evaluated lazily, once /// enumeration has begun. The value returned by will be disposed after the - /// enumeration has completed. + /// enumeration has completed. /// /// /// The values returned by and are not diff --git a/Source/SuperLinq.Async/Where.cs b/Source/SuperLinq.Async/Where.cs index 3512d683f..33599ceed 100644 --- a/Source/SuperLinq.Async/Where.cs +++ b/Source/SuperLinq.Async/Where.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -9,7 +9,7 @@ public static partial class AsyncSuperEnumerable /// An to filter. /// An of boolean values identifying which elements of to keep. /// - /// An that contains elements from the input sequence + /// An that contains elements from the input sequence /// where the matching value in is . /// /// is . @@ -21,7 +21,11 @@ public static IAsyncEnumerable Where(this IAsyncEnumerable Core(IAsyncEnumerable source, IAsyncEnumerable filter, [EnumeratorCancellation] CancellationToken cancellation = default) + static async IAsyncEnumerable Core( + IAsyncEnumerable source, + IAsyncEnumerable filter, + [EnumeratorCancellation] CancellationToken cancellation = default + ) { await using var sIter = source.GetConfiguredAsyncEnumerator(cancellation); await using var fIter = filter.GetConfiguredAsyncEnumerator(cancellation); diff --git a/Source/SuperLinq.Async/WhereLag.cs b/Source/SuperLinq.Async/WhereLag.cs index 8651d13b5..b56ebc11b 100644 --- a/Source/SuperLinq.Async/WhereLag.cs +++ b/Source/SuperLinq.Async/WhereLag.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -25,7 +25,11 @@ public static partial class AsyncSuperEnumerable /// This operator evaluates in a deferred and streaming manner. /// /// - public static IAsyncEnumerable WhereLag(this IAsyncEnumerable source, int offset, Func predicate) + public static IAsyncEnumerable WhereLag( + this IAsyncEnumerable source, + int offset, + Func predicate + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(predicate); @@ -57,7 +61,11 @@ public static IAsyncEnumerable WhereLag(this IAsyncEnumerable< /// This operator evaluates in a deferred and streaming manner. /// /// - public static IAsyncEnumerable WhereLag(this IAsyncEnumerable source, int offset, Func> predicate) + public static IAsyncEnumerable WhereLag( + this IAsyncEnumerable source, + int offset, + Func> predicate + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(predicate); @@ -86,7 +94,12 @@ public static IAsyncEnumerable WhereLag(this IAsyncEnumerable< /// This operator evaluates in a deferred and streaming manner. /// /// - public static IAsyncEnumerable WhereLag(this IAsyncEnumerable source, int offset, TSource defaultLagValue, Func predicate) + public static IAsyncEnumerable WhereLag( + this IAsyncEnumerable source, + int offset, + TSource defaultLagValue, + Func predicate + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(predicate); @@ -115,7 +128,12 @@ public static IAsyncEnumerable WhereLag(this IAsyncEnumerable< /// This operator evaluates in a deferred and streaming manner. /// /// - public static IAsyncEnumerable WhereLag(this IAsyncEnumerable source, int offset, TSource defaultLagValue, Func> predicate) + public static IAsyncEnumerable WhereLag( + this IAsyncEnumerable source, + int offset, + TSource defaultLagValue, + Func> predicate + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(predicate); @@ -124,8 +142,12 @@ public static IAsyncEnumerable WhereLag(this IAsyncEnumerable< return Core(source, offset, defaultLagValue, predicate); static async IAsyncEnumerable Core( - IAsyncEnumerable source, int offset, TSource defaultLagValue, Func> predicate, - [EnumeratorCancellation] CancellationToken cancellationToken = default) + IAsyncEnumerable source, + int offset, + TSource defaultLagValue, + Func> predicate, + [EnumeratorCancellation] CancellationToken cancellationToken = default + ) { var lagQueue = new Queue(offset + 1); await foreach (var item in source.WithCancellation(cancellationToken).ConfigureAwait(false)) diff --git a/Source/SuperLinq.Async/WhereLead.cs b/Source/SuperLinq.Async/WhereLead.cs index f03e7ca47..c4b37efa9 100644 --- a/Source/SuperLinq.Async/WhereLead.cs +++ b/Source/SuperLinq.Async/WhereLead.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -25,7 +25,11 @@ public static partial class AsyncSuperEnumerable /// This operator evaluates in a deferred and streaming manner. /// /// - public static IAsyncEnumerable WhereLead(this IAsyncEnumerable source, int offset, Func predicate) + public static IAsyncEnumerable WhereLead( + this IAsyncEnumerable source, + int offset, + Func predicate + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(predicate); @@ -57,7 +61,11 @@ public static IAsyncEnumerable WhereLead(this IAsyncEnumerable /// This operator evaluates in a deferred and streaming manner. /// /// - public static IAsyncEnumerable WhereLead(this IAsyncEnumerable source, int offset, Func> predicate) + public static IAsyncEnumerable WhereLead( + this IAsyncEnumerable source, + int offset, + Func> predicate + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(predicate); @@ -86,7 +94,12 @@ public static IAsyncEnumerable WhereLead(this IAsyncEnumerable /// This operator evaluates in a deferred and streaming manner. /// /// - public static IAsyncEnumerable WhereLead(this IAsyncEnumerable source, int offset, TSource defaultLeadValue, Func predicate) + public static IAsyncEnumerable WhereLead( + this IAsyncEnumerable source, + int offset, + TSource defaultLeadValue, + Func predicate + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(predicate); @@ -115,7 +128,12 @@ public static IAsyncEnumerable WhereLead(this IAsyncEnumerable /// This operator evaluates in a deferred and streaming manner. /// /// - public static IAsyncEnumerable WhereLead(this IAsyncEnumerable source, int offset, TSource defaultLeadValue, Func> predicate) + public static IAsyncEnumerable WhereLead( + this IAsyncEnumerable source, + int offset, + TSource defaultLeadValue, + Func> predicate + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(predicate); diff --git a/Source/SuperLinq.Async/Window.cs b/Source/SuperLinq.Async/Window.cs index 9d37c9cd9..23a4beb28 100644 --- a/Source/SuperLinq.Async/Window.cs +++ b/Source/SuperLinq.Async/Window.cs @@ -35,6 +35,7 @@ static async IAsyncEnumerable> Core( { if (!await e.MoveNextAsync()) yield break; + window[i] = e.Current; } diff --git a/Source/SuperLinq.Async/ZipMap.cs b/Source/SuperLinq.Async/ZipMap.cs index c59b27108..205caf9f0 100644 --- a/Source/SuperLinq.Async/ZipMap.cs +++ b/Source/SuperLinq.Async/ZipMap.cs @@ -1,4 +1,4 @@ -namespace SuperLinq.Async; +namespace SuperLinq.Async; public static partial class AsyncSuperEnumerable { @@ -17,7 +17,10 @@ public static partial class AsyncSuperEnumerable /// /// is . /// is . - public static IAsyncEnumerable<(TSource item, TResult result)> ZipMap(this IAsyncEnumerable source, Func selector) + public static IAsyncEnumerable<(TSource item, TResult result)> ZipMap( + this IAsyncEnumerable source, + Func selector + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(selector); @@ -40,7 +43,10 @@ public static partial class AsyncSuperEnumerable /// /// is . /// is . - public static IAsyncEnumerable<(TSource item, TResult result)> ZipMap(this IAsyncEnumerable source, Func> selector) + public static IAsyncEnumerable<(TSource item, TResult result)> ZipMap( + this IAsyncEnumerable source, + Func> selector + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(selector); @@ -63,7 +69,10 @@ public static partial class AsyncSuperEnumerable /// /// is . /// is . - public static IAsyncEnumerable<(TSource item, TResult result)> ZipMap(this IAsyncEnumerable source, Func> selector) + public static IAsyncEnumerable<(TSource item, TResult result)> ZipMap( + this IAsyncEnumerable source, + Func> selector + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(selector); diff --git a/Source/SuperLinq/AggregateRight.cs b/Source/SuperLinq/AggregateRight.cs index 3dbab8adc..6f1833d7d 100644 --- a/Source/SuperLinq/AggregateRight.cs +++ b/Source/SuperLinq/AggregateRight.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { @@ -73,7 +73,11 @@ public static TSource AggregateRight(this IEnumerable source, /// /// This operator executes immediately. /// - public static TAccumulate AggregateRight(this IEnumerable source, TAccumulate seed, Func func) + public static TAccumulate AggregateRight( + this IEnumerable source, + TAccumulate seed, + Func func + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(func); @@ -124,7 +128,12 @@ public static TAccumulate AggregateRight(this IEnumerable< /// /// This operator executes immediately. /// - public static TResult AggregateRight(this IEnumerable source, TAccumulate seed, Func func, Func resultSelector) + public static TResult AggregateRight( + this IEnumerable source, + TAccumulate seed, + Func func, + Func resultSelector + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(func); diff --git a/Source/SuperLinq/AssertCount.cs b/Source/SuperLinq/AssertCount.cs index db262b9d6..77a5227af 100644 --- a/Source/SuperLinq/AssertCount.cs +++ b/Source/SuperLinq/AssertCount.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { @@ -50,6 +50,7 @@ static IEnumerable Core(IEnumerable source, int count) { if (++c > count) break; + yield return item; } @@ -107,9 +108,7 @@ protected override IEnumerable GetEnumerable() { var cnt = (uint)Count; for (var i = 0; i < cnt; i++) - { yield return source[i]; - } } public override void CopyTo(T[] array, int arrayIndex) diff --git a/Source/SuperLinq/BindByIndex.cs b/Source/SuperLinq/BindByIndex.cs index c2a7c11ca..293a12fbe 100644 --- a/Source/SuperLinq/BindByIndex.cs +++ b/Source/SuperLinq/BindByIndex.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { @@ -34,7 +34,15 @@ public static IEnumerable BindByIndex( this IEnumerable source, IEnumerable indices) { - return BindByIndex(source, indices, static (e, i) => e, static i => ThrowHelper.ThrowArgumentOutOfRangeException(nameof(indices), "Index is greater than the length of the first sequence.")); + return BindByIndex( + source, + indices, + static (e, i) => e, + static i => ThrowHelper.ThrowArgumentOutOfRangeException( + nameof(indices), + "Index is greater than the length of the first sequence." + ) + ); } /// @@ -86,10 +94,25 @@ public static IEnumerable BindByIndex( return Core(source, indices, resultSelector, missingSelector); - static IEnumerable Core(IEnumerable source, IEnumerable indices, Func resultSelector, Func missingSelector) + static IEnumerable Core( + IEnumerable source, + IEnumerable indices, + Func resultSelector, + Func missingSelector + ) { // keeps track of the order of indices to know what order items should be output in - var lookup = indices.Index().ToDictionary(x => { ArgumentOutOfRangeException.ThrowIfNegative(x.Item, nameof(indices)); return x.Item; }, x => x.Index); + var lookup = indices + .Index() + .ToDictionary( + x => + { + ArgumentOutOfRangeException.ThrowIfNegative(x.Item, nameof(indices)); + return x.Item; + }, + x => x.Index + ); + // keep track of items out of output order var lookback = new Dictionary(); diff --git a/Source/SuperLinq/Catch.cs b/Source/SuperLinq/Catch.cs index 37eab3a00..64c08cd69 100644 --- a/Source/SuperLinq/Catch.cs +++ b/Source/SuperLinq/Catch.cs @@ -97,7 +97,7 @@ public static IEnumerable Catch(this IEnumerable firs ArgumentNullException.ThrowIfNull(first); ArgumentNullException.ThrowIfNull(second); - return Catch(new[] { first, second, }); + return Catch(new[] { first, second }); } /// diff --git a/Source/SuperLinq/CollectionIterator.cs b/Source/SuperLinq/CollectionIterator.cs index 162d56165..781afeb23 100644 --- a/Source/SuperLinq/CollectionIterator.cs +++ b/Source/SuperLinq/CollectionIterator.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections; using System.Diagnostics.CodeAnalysis; namespace SuperLinq; @@ -9,10 +9,13 @@ public partial class SuperEnumerable private abstract class CollectionIterator : ICollection, IReadOnlyCollection { public bool IsReadOnly => true; + public void Add(T item) => ThrowHelper.ThrowNotSupportedException(); + public bool Remove(T item) => ThrowHelper.ThrowNotSupportedException(); + public void Clear() => ThrowHelper.ThrowNotSupportedException(); diff --git a/Source/SuperLinq/Collections/NullKeyDictionary.cs b/Source/SuperLinq/Collections/NullKeyDictionary.cs index df94ebf7c..ccc0af6da 100644 --- a/Source/SuperLinq/Collections/NullKeyDictionary.cs +++ b/Source/SuperLinq/Collections/NullKeyDictionary.cs @@ -1,4 +1,4 @@ -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; namespace SuperLinq.Collections; @@ -23,9 +23,9 @@ public TValue this[TKey key] set => this[ValueTuple.Create(key)] = value; } - public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value) - => this.TryGetValue(ValueTuple.Create(key), out value); + public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value) => + TryGetValue(ValueTuple.Create(key), out value); - public bool Remove(TKey key) - => this.Remove(ValueTuple.Create(key)); + public bool Remove(TKey key) => + Remove(ValueTuple.Create(key)); } diff --git a/Source/SuperLinq/Collections/UpdatablePriorityQueue.cs b/Source/SuperLinq/Collections/UpdatablePriorityQueue.cs index 75c53a95c..7c78e3db7 100644 --- a/Source/SuperLinq/Collections/UpdatablePriorityQueue.cs +++ b/Source/SuperLinq/Collections/UpdatablePriorityQueue.cs @@ -91,8 +91,7 @@ public UpdatablePriorityQueue() /// public UpdatablePriorityQueue(int initialCapacity) : this(initialCapacity, priorityComparer: null, elementComparer: null) - { - } + { } /// /// Initializes a new instance of the class @@ -165,8 +164,7 @@ public UpdatablePriorityQueue(int initialCapacity, IComparer? priorit /// public UpdatablePriorityQueue(IEnumerable<(TElement Element, TPriority Priority)> items) : this(items, priorityComparer: null, elementComparer: null) - { - } + { } /// /// Initializes a new instance of the class @@ -189,7 +187,11 @@ public UpdatablePriorityQueue(IEnumerable<(TElement Element, TPriority Priority) /// Constructs the heap using a heapify operation, /// which is generally faster than enqueuing individual elements sequentially. /// - public UpdatablePriorityQueue(IEnumerable<(TElement Element, TPriority Priority)> items, IComparer? priorityComparer, IEqualityComparer? elementComparer) + public UpdatablePriorityQueue( + IEnumerable<(TElement Element, TPriority Priority)> items, + IComparer? priorityComparer, + IEqualityComparer? elementComparer + ) { ArgumentNullException.ThrowIfNull(items); @@ -200,9 +202,7 @@ public UpdatablePriorityQueue(IEnumerable<(TElement Element, TPriority Priority) Count = _nodes.Length; if (Count > 1) - { Heapify(); - } } /// @@ -222,7 +222,8 @@ public UpdatablePriorityQueue(IEnumerable<(TElement Element, TPriority Priority) /// The enumeration does not order items by priority, since that would require N * log(N) time and N space. /// Items are instead enumerated following the internal array heap layout. /// - public IReadOnlyCollection<(TElement Element, TPriority Priority)> UnorderedItems => _unorderedItems ??= new UnorderedItemsCollection(this); + public IReadOnlyCollection<(TElement Element, TPriority Priority)> UnorderedItems => + _unorderedItems ??= new UnorderedItemsCollection(this); /// /// Adds or updates the specified element with associated priority to the . @@ -261,18 +262,12 @@ public void Enqueue(TElement element, TPriority priority) var currentSize = Count++; if (_nodes.Length == currentSize) - { Grow(currentSize + 1); - } if (_priorityComparer is null) - { MoveUpDefaultComparer((element, priority), currentSize); - } else - { MoveUpCustomComparer((element, priority), currentSize); - } } } @@ -310,18 +305,12 @@ public void EnqueueMinimum(TElement element, TPriority priority) var currentSize = Count++; if (_nodes.Length == currentSize) - { Grow(currentSize + 1); - } if (_priorityComparer is null) - { MoveUpDefaultComparer((element, priority), currentSize); - } else - { MoveUpCustomComparer((element, priority), currentSize); - } } } @@ -333,9 +322,7 @@ public void EnqueueMinimum(TElement element, TPriority priority) public TElement Peek() { if (Count == 0) - { ThrowHelper.ThrowInvalidOperationException("Queue empty."); - } return _nodes[0].Element; } @@ -348,9 +335,7 @@ public TElement Peek() public TElement Dequeue() { if (Count == 0) - { ThrowHelper.ThrowInvalidOperationException("Queue empty."); - } var element = _nodes[0].Element; RemoveRootNode(); @@ -435,14 +420,11 @@ public TElement EnqueueDequeue(TElement element, TPriority priority) return rootElement; } } - else + else if (_priorityComparer.Compare(priority, rootPriority) > 0) { - if (_priorityComparer.Compare(priority, rootPriority) > 0) - { - MoveDownCustomComparer((element, priority), 0); - _version++; - return rootElement; - } + MoveDownCustomComparer((element, priority), 0); + _version++; + return rootElement; } } @@ -464,9 +446,7 @@ public void EnqueueRange(IEnumerable<(TElement Element, TPriority Priority)> ite var count = 0; var collection = items as ICollection<(TElement Element, TPriority Priority)>; if (collection is not null && (count = collection.Count) > _nodes.Length - Count) - { Grow(Count + count); - } if (Count == 0) { @@ -498,16 +478,12 @@ public void EnqueueRange(IEnumerable<(TElement Element, TPriority Priority)> ite _version++; if (Count > 1) - { Heapify(); - } } else { foreach (var (element, priority) in items) - { Enqueue(element, priority); - } } } @@ -526,8 +502,8 @@ public void EnqueueRange(IEnumerable elements, TPriority priority) ArgumentNullException.ThrowIfNull(elements); int count; - if (elements is ICollection<(TElement Element, TPriority Priority)> collection && - (count = collection.Count) > _nodes.Length - Count) + if (elements is ICollection<(TElement Element, TPriority Priority)> collection + && (count = collection.Count) > _nodes.Length - Count) { Grow(Count + count); } @@ -553,16 +529,12 @@ public void EnqueueRange(IEnumerable elements, TPriority priority) _version++; if (i > 1) - { Heapify(); - } } else { foreach (var element in elements) - { Enqueue(element, priority); - } } } @@ -581,9 +553,7 @@ public void EnqueueRangeMinimum(IEnumerable<(TElement Element, TPriority Priorit var count = 0; var collection = items as ICollection<(TElement Element, TPriority Priority)>; if (collection is not null && (count = collection.Count) > _nodes.Length - Count) - { Grow(Count + count); - } if (Count == 0) { @@ -615,16 +585,12 @@ public void EnqueueRangeMinimum(IEnumerable<(TElement Element, TPriority Priorit _version++; if (Count > 1) - { Heapify(); - } } else { foreach (var (element, priority) in items) - { EnqueueMinimum(element, priority); - } } } @@ -643,8 +609,8 @@ public void EnqueueRangeMinimum(IEnumerable elements, TPriority priori ArgumentNullException.ThrowIfNull(elements); int count; - if (elements is ICollection<(TElement Element, TPriority Priority)> collection && - (count = collection.Count) > _nodes.Length - Count) + if (elements is ICollection<(TElement Element, TPriority Priority)> collection + && (count = collection.Count) > _nodes.Length - Count) { Grow(Count + count); } @@ -670,16 +636,12 @@ public void EnqueueRangeMinimum(IEnumerable elements, TPriority priori _version++; if (i > 1) - { Heapify(); - } } else { foreach (var element in elements) - { EnqueueMinimum(element, priority); - } } } @@ -753,14 +715,16 @@ private void Grow(int minCapacity) // Allow the queue to grow to maximum possible capacity (~2G elements) before encountering overflow. // Note that this check works even when _nodes.Length overflowed thanks to the (uint) cast - if ((uint)newcapacity > int.MaxValue) newcapacity = int.MaxValue; + if ((uint)newcapacity > int.MaxValue) + newcapacity = int.MaxValue; // Ensure minimum growth is respected. newcapacity = Math.Max(newcapacity, _nodes.Length + MinimumGrow); // If the computed capacity is still less than specified, set to the original argument. // Capacities exceeding Array.MaxLength will be surfaced as OutOfMemoryException by Array.Resize. - if (newcapacity < minCapacity) newcapacity = minCapacity; + if (newcapacity < minCapacity) + newcapacity = minCapacity; Array.Resize(ref _nodes, newcapacity); } @@ -779,19 +743,13 @@ private void RemoveRootNode() { var lastNode = _nodes[lastNodeIndex]; if (_priorityComparer is null) - { MoveDownDefaultComparer(lastNode, 0); - } else - { MoveDownCustomComparer(lastNode, 0); - } } if (RuntimeHelpers.IsReferenceOrContainsReferences<(TElement, TPriority)>()) - { _nodes[lastNodeIndex] = default; - } } /// @@ -843,16 +801,12 @@ private void Heapify() if (_priorityComparer is null) { for (var index = lastParentWithChildren; index >= 0; --index) - { MoveDownDefaultComparer(nodes[index], index); - } } else { for (var index = lastParentWithChildren; index >= 0; --index) - { MoveDownCustomComparer(nodes[index], index); - } } } @@ -962,9 +916,7 @@ private void MoveDownDefaultComparer((TElement Element, TPriority Priority) node // Heap property is satisfied; insert node in this location. if (Comparer.Default.Compare(node.Priority, minChild.Priority) <= 0) - { break; - } // Move the minimal child up by one node and // continue recursively from its location. @@ -1014,9 +966,7 @@ private void MoveDownCustomComparer((TElement Element, TPriority Priority) node, // Heap property is satisfied; insert node in this location. if (comparer.Compare(node.Priority, minChild.Priority) <= 0) - { break; - } // Move the minimal child up by one node and continue recursively from its location. nodes[nodeIndex] = minChild; @@ -1158,7 +1108,8 @@ void IEnumerator.Reset() /// An for the . public Enumerator GetEnumerator() => new(_queue); - IEnumerator<(TElement Element, TPriority Priority)> IEnumerable<(TElement Element, TPriority Priority)>.GetEnumerator() => GetEnumerator(); + IEnumerator<(TElement Element, TPriority Priority)> IEnumerable<(TElement Element, TPriority Priority)>.GetEnumerator() => + GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } @@ -1191,9 +1142,7 @@ public PriorityQueueDebugView(UpdatablePriorityQueue.Unorde { var list = new List<(TElement Element, TPriority Priority)>(_queue.UnorderedItems); if (_sort) - { list.Sort((i1, i2) => _queue.Comparer.Compare(i1.Priority, i2.Priority)); - } return [.. list]; } diff --git a/Source/SuperLinq/Consume.cs b/Source/SuperLinq/Consume.cs index b06e3f240..4d19c8f56 100644 --- a/Source/SuperLinq/Consume.cs +++ b/Source/SuperLinq/Consume.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { @@ -17,7 +17,7 @@ public static partial class SuperEnumerable /// /// /// The purpose of this method is to execute the operators for the provided , in the - /// event that the operators have side-effects. + /// event that the operators have side-effects. /// /// /// This method executes immediately. @@ -27,7 +27,6 @@ public static void Consume(this IEnumerable source) { ArgumentNullException.ThrowIfNull(source); foreach (var _ in source) - { - } + { } } } diff --git a/Source/SuperLinq/CopyTo.cs b/Source/SuperLinq/CopyTo.cs index 816799af4..9ce7ad398 100644 --- a/Source/SuperLinq/CopyTo.cs +++ b/Source/SuperLinq/CopyTo.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { @@ -258,6 +258,7 @@ public static int CopyTo(this IEnumerable source, IList /// /// This method is implemented by using deferred execution. However, will be consumed - /// in it's entirety immediately when first element of the returned sequence is consumed. + /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// #if NET9_0_OR_GREATER [Obsolete("This method has been implemented by the framework.")] - public static IEnumerable> CountBy(IEnumerable source, Func keySelector) + public static IEnumerable> CountBy( + IEnumerable source, + Func keySelector + ) #else - public static IEnumerable> CountBy(this IEnumerable source, Func keySelector) + public static IEnumerable> CountBy( + this IEnumerable source, + Func keySelector + ) #endif { return CountBy(source, keySelector, comparer: null); @@ -70,14 +76,22 @@ public static IEnumerable> CountBy(this I /// /// /// This method is implemented by using deferred execution. However, will be consumed - /// in it's entirety immediately when first element of the returned sequence is consumed. + /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// #if NET9_0_OR_GREATER [Obsolete("This method has been implemented by the framework.")] - public static IEnumerable> CountBy(IEnumerable source, Func keySelector, IEqualityComparer? comparer) + public static IEnumerable> CountBy( + IEnumerable source, + Func keySelector, + IEqualityComparer? comparer + ) #else - public static IEnumerable> CountBy(this IEnumerable source, Func keySelector, IEqualityComparer? comparer) + public static IEnumerable> CountBy( + this IEnumerable source, + Func keySelector, + IEqualityComparer? comparer + ) #endif { ArgumentNullException.ThrowIfNull(source); @@ -85,7 +99,11 @@ public static IEnumerable> CountBy(this I return Core(source, keySelector, comparer ?? EqualityComparer.Default); - static IEnumerable> Core(IEnumerable source, Func keySelector, IEqualityComparer comparer) + static IEnumerable> Core( + IEnumerable source, + Func keySelector, + IEqualityComparer comparer + ) { // Avoid the temptation to inline the Loop method, which // exists solely to separate the scope & lifetimes of the diff --git a/Source/SuperLinq/DensePartialSort.cs b/Source/SuperLinq/DensePartialSort.cs index 78b2af04a..1e1074c73 100644 --- a/Source/SuperLinq/DensePartialSort.cs +++ b/Source/SuperLinq/DensePartialSort.cs @@ -33,7 +33,7 @@ public static partial class SuperEnumerable /// /// /// This method is implemented by using deferred execution. However, will be consumed - /// in it's entirety immediately when first element of the returned sequence is consumed. + /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// /// This method performs a stable sort; that is, if the keys of two elements are equal, the order of the @@ -78,7 +78,7 @@ public static IEnumerable DensePartialSort(this IEnumerable source, int /// /// /// This method is implemented by using deferred execution. However, will be consumed - /// in it's entirety immediately when first element of the returned sequence is consumed. + /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// /// This method performs a stable sort; that is, if the keys of two elements are equal, the order of the @@ -124,7 +124,7 @@ public static IEnumerable DensePartialSort( /// /// /// This method is implemented by using deferred execution. However, will be consumed - /// in it's entirety immediately when first element of the returned sequence is consumed. + /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// /// This method performs a stable sort; that is, if the keys of two elements are equal, the order of the @@ -175,7 +175,7 @@ public static IEnumerable DensePartialSort( /// /// /// This method is implemented by using deferred execution. However, will be consumed - /// in it's entirety immediately when first element of the returned sequence is consumed. + /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// /// This method performs a stable sort; that is, if the keys of two elements are equal, the order of the @@ -204,12 +204,12 @@ public static IEnumerable DensePartialSort( /// /// The source sequence. /// - /// - /// A function to extract a key from an element. - /// /// /// Number of (maximum) elements to return. /// + /// + /// A function to extract a key from an element. + /// /// /// A sequence containing at most top elements from source, in ascending order of their /// keys. @@ -225,7 +225,7 @@ public static IEnumerable DensePartialSort( /// /// /// This method is implemented by using deferred execution. However, will be consumed - /// in it's entirety immediately when first element of the returned sequence is consumed. + /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// /// This method performs a stable sort; that is, if the keys of two elements are equal, the order of the @@ -254,12 +254,12 @@ public static IEnumerable DensePartialSortBy( /// /// The source sequence. /// - /// - /// A function to extract a key from an element. - /// /// /// Number of (maximum) elements to return. /// + /// + /// A function to extract a key from an element. + /// /// /// The direction in which to sort the elements /// @@ -278,7 +278,7 @@ public static IEnumerable DensePartialSortBy( /// /// /// This method is implemented by using deferred execution. However, will be consumed - /// in it's entirety immediately when first element of the returned sequence is consumed. + /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// /// This method performs a stable sort; that is, if the keys of two elements are equal, the order of the @@ -308,12 +308,12 @@ public static IEnumerable DensePartialSortBy( /// /// The source sequence. /// - /// - /// A function to extract a key from an element. - /// /// /// Number of (maximum) elements to return. /// + /// + /// A function to extract a key from an element. + /// /// /// A to compare elements. /// @@ -332,7 +332,7 @@ public static IEnumerable DensePartialSortBy( /// /// /// This method is implemented by using deferred execution. However, will be consumed - /// in it's entirety immediately when first element of the returned sequence is consumed. + /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// /// This method performs a stable sort; that is, if the keys of two elements are equal, the order of the @@ -363,12 +363,12 @@ public static IEnumerable DensePartialSortBy( /// /// The source sequence. /// - /// - /// A function to extract a key from an element. - /// /// /// Number of (maximum) elements to return. /// + /// + /// A function to extract a key from an element. + /// /// /// A to compare elements. /// @@ -390,7 +390,7 @@ public static IEnumerable DensePartialSortBy( /// /// /// This method is implemented by using deferred execution. However, will be consumed - /// in it's entirety immediately when first element of the returned sequence is consumed. + /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// /// This method performs a stable sort; that is, if the keys of two elements are equal, the order of the diff --git a/Source/SuperLinq/DistinctUntilChanged.cs b/Source/SuperLinq/DistinctUntilChanged.cs index 809a28ae4..e6a343685 100644 --- a/Source/SuperLinq/DistinctUntilChanged.cs +++ b/Source/SuperLinq/DistinctUntilChanged.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { @@ -118,7 +118,11 @@ public static IEnumerable DistinctUntilChanged(this IEnu /// This method uses deferred execution semantics and streams its results. /// /// - public static IEnumerable DistinctUntilChanged(this IEnumerable source, Func keySelector, IEqualityComparer? comparer) + public static IEnumerable DistinctUntilChanged( + this IEnumerable source, + Func keySelector, + IEqualityComparer? comparer + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(keySelector); diff --git a/Source/SuperLinq/Do.cs b/Source/SuperLinq/Do.cs index 7afd957f1..58d9dd0a2 100644 --- a/Source/SuperLinq/Do.cs +++ b/Source/SuperLinq/Do.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public partial class SuperEnumerable { @@ -145,7 +145,12 @@ public static IEnumerable Do(this IEnumerable source, /// This method uses deferred execution and streams its results. /// /// - public static IEnumerable Do(this IEnumerable source, Action onNext, Action onError, Action onCompleted) + public static IEnumerable Do( + this IEnumerable source, + Action onNext, + Action onError, + Action onCompleted + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(onNext); @@ -155,7 +160,12 @@ public static IEnumerable Do(this IEnumerable source, return DoCore(source, onNext, onError, onCompleted); } - private static IEnumerable DoCore(IEnumerable source, Action onNext, Action onError, Action onCompleted) + private static IEnumerable DoCore( + IEnumerable source, + Action onNext, + Action onError, + Action onCompleted + ) { using var iter = source.GetEnumerator(); while (true) diff --git a/Source/SuperLinq/DoWhile.cs b/Source/SuperLinq/DoWhile.cs index f52de2240..ed1388b45 100644 --- a/Source/SuperLinq/DoWhile.cs +++ b/Source/SuperLinq/DoWhile.cs @@ -46,7 +46,8 @@ static IEnumerable Core(IEnumerable source, Func conditi { foreach (var item in memo) yield return item; - } while (condition()); + } + while (condition()); } } } diff --git a/Source/SuperLinq/ElementAt.cs b/Source/SuperLinq/ElementAt.cs index 68b1ed8ef..df2c91206 100644 --- a/Source/SuperLinq/ElementAt.cs +++ b/Source/SuperLinq/ElementAt.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics.CodeAnalysis; @@ -52,19 +52,13 @@ public static TSource ElementAt(this IEnumerable source, Index ArgumentNullException.ThrowIfNull(source); if (!index.IsFromEnd) - { return Enumerable.ElementAt(source, index.Value); - } if (source is ICollection c) - { return Enumerable.ElementAt(source, c.Count - index.Value); - } if (!TryGetElementFromEnd(source, index.Value, out var element)) - { ThrowHelper.ThrowArgumentOutOfRangeException(nameof(index)); - } return element; } @@ -108,20 +102,20 @@ public static TSource ElementAt(this IEnumerable source, Index ArgumentNullException.ThrowIfNull(source); if (!index.IsFromEnd) - { return Enumerable.ElementAt(source, index.Value); - } if (source.TryGetCollectionCount() is int count) - { return Enumerable.ElementAt(source, count - index.Value); - } _ = TryGetElementFromEnd(source, index.Value, out var element); return element; } - private static bool TryGetElementFromEnd(IEnumerable source, int indexFromEnd, [MaybeNullWhen(false)] out TSource element) + private static bool TryGetElementFromEnd( + IEnumerable source, + int indexFromEnd, + [MaybeNullWhen(false)] out TSource element + ) { if (indexFromEnd > 0) { @@ -133,9 +127,7 @@ private static bool TryGetElementFromEnd(IEnumerable source, i while (e.MoveNext()) { if (queue.Count == indexFromEnd) - { _ = queue.Dequeue(); - } queue.Enqueue(e.Current); } diff --git a/Source/SuperLinq/EndsWith.cs b/Source/SuperLinq/EndsWith.cs index 98b3abc63..05564cb1c 100644 --- a/Source/SuperLinq/EndsWith.cs +++ b/Source/SuperLinq/EndsWith.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { @@ -65,9 +65,9 @@ public static bool EndsWith(this IEnumerable first, IEnumerable second, ArgumentNullException.ThrowIfNull(first); ArgumentNullException.ThrowIfNull(second); - if (first.TryGetCollectionCount() is int firstCount && - second.TryGetCollectionCount() is int secondCount && - secondCount > firstCount) + if (first.TryGetCollectionCount() is int firstCount + && second.TryGetCollectionCount() is int secondCount + && secondCount > firstCount) { return false; } diff --git a/Source/SuperLinq/ExceptBy.cs b/Source/SuperLinq/ExceptBy.cs index d070f0b98..501b8d19e 100644 --- a/Source/SuperLinq/ExceptBy.cs +++ b/Source/SuperLinq/ExceptBy.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { @@ -92,7 +92,12 @@ public static IEnumerable ExceptBy( return Core(first, second, keySelector, keyComparer); - static IEnumerable Core(IEnumerable first, IEnumerable second, Func keySelector, IEqualityComparer? keyComparer) + static IEnumerable Core( + IEnumerable first, + IEnumerable second, + Func keySelector, + IEqualityComparer? keyComparer + ) { var keys = second.Select(keySelector).ToHashSet(keyComparer); foreach (var element in first) @@ -100,6 +105,7 @@ static IEnumerable Core(IEnumerable first, IEnumerable Exclude(this IEnumerable sequence, Range rang var startFromEnd = range.Start.IsFromEnd; var endFromEnd = range.End.IsFromEnd; + if ((startFromEnd, endFromEnd) == (false, false)) - { return Exclude(sequence, range.Start.Value, range.End.Value - range.Start.Value); - } if (sequence.TryGetCollectionCount() is int count) { @@ -110,7 +109,7 @@ private sealed class ExcludeCollectionIterator(ICollection source, int sta source.Count < startIndex + count ? startIndex : source.Count - count; - /// + /// protected override IEnumerable GetEnumerable() => ExcludeCore(source, startIndex, count); } @@ -180,6 +179,7 @@ private static IEnumerable ExcludeRange(IEnumerable sequence, Range ran { if (!queue.TryDequeue(out var _)) yield break; + length--; } @@ -207,6 +207,7 @@ private static IEnumerable ExcludeStartFromEnd(IEnumerable sequence, Ra { if (!queue.TryDequeue(out var _)) yield break; + length--; } diff --git a/Source/SuperLinq/FallbackIfEmpty.cs b/Source/SuperLinq/FallbackIfEmpty.cs index 36406933d..e56e776e3 100644 --- a/Source/SuperLinq/FallbackIfEmpty.cs +++ b/Source/SuperLinq/FallbackIfEmpty.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { @@ -68,7 +68,7 @@ public static IEnumerable FallbackIfEmpty(this IEnumerable source, IEnu ArgumentNullException.ThrowIfNull(fallback); return source.TryGetCollectionCount() is not null - && fallback.TryGetCollectionCount() is not null + && fallback.TryGetCollectionCount() is not null ? new FallbackIfEmptyCollectionIterator(source, fallback) : Core(source, fallback); @@ -81,7 +81,8 @@ static IEnumerable Core(IEnumerable source, IEnumerable fallback) do { yield return e.Current; - } while (e.MoveNext()); + } + while (e.MoveNext()); yield break; } diff --git a/Source/SuperLinq/FillBackward.cs b/Source/SuperLinq/FillBackward.cs index 0dbc822a5..3f9f10877 100644 --- a/Source/SuperLinq/FillBackward.cs +++ b/Source/SuperLinq/FillBackward.cs @@ -176,7 +176,9 @@ public override void CopyTo(T[] array, int arrayIndex) : last; } else + { last = array[i]; + } } } } diff --git a/Source/SuperLinq/FillForward.cs b/Source/SuperLinq/FillForward.cs index 9bf75ffbb..52b4c2d76 100644 --- a/Source/SuperLinq/FillForward.cs +++ b/Source/SuperLinq/FillForward.cs @@ -167,7 +167,9 @@ public override void CopyTo(T[] array, int arrayIndex) : last; } else + { last = array[i]; + } } } } diff --git a/Source/SuperLinq/FindIndex.cs b/Source/SuperLinq/FindIndex.cs index 980cf8779..2ec725dad 100644 --- a/Source/SuperLinq/FindIndex.cs +++ b/Source/SuperLinq/FindIndex.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { @@ -30,7 +30,7 @@ public static partial class SuperEnumerable /// /// The is a delegate to a method that returns if the object /// passed to it matches the conditions defined in the delegate. The elements of the current are individually passed to the delegate. + /// cref="IEnumerable{T}"/> are individually passed to the delegate. /// /// /// This operator executes immediately. @@ -74,7 +74,7 @@ public static int FindIndex(this IEnumerable source, Func /// The is a delegate to a method that returns if the object /// passed to it matches the conditions defined in the delegate. The elements of the current are individually passed to the delegate. + /// cref="IEnumerable{T}"/> are individually passed to the delegate. /// /// /// This operator executes immediately. @@ -124,7 +124,7 @@ public static int FindIndex(this IEnumerable source, Func /// The is a delegate to a method that returns if the object /// passed to it matches the conditions defined in the delegate. The elements of the current are individually passed to the delegate. + /// cref="IEnumerable{T}"/> are individually passed to the delegate. /// /// /// This operator executes immediately. @@ -137,9 +137,7 @@ public static int FindIndex(this IEnumerable source, Func(this IEnumerable source, Func= count) return -1; } @@ -187,8 +186,10 @@ public static int FindIndex(this IEnumerable source, Func= count) return -1; + i++; } } diff --git a/Source/SuperLinq/FindLastIndex.cs b/Source/SuperLinq/FindLastIndex.cs index 052b9ded2..023daf8b0 100644 --- a/Source/SuperLinq/FindLastIndex.cs +++ b/Source/SuperLinq/FindLastIndex.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { @@ -31,7 +31,7 @@ public static partial class SuperEnumerable /// /// The is a delegate to a method that returns if the object /// passed to it matches the conditions defined in the delegate. The elements of the current are individually passed to the delegate. + /// cref="IEnumerable{T}"/> are individually passed to the delegate. /// /// /// This operator executes immediately. @@ -76,7 +76,7 @@ public static int FindLastIndex(this IEnumerable source, Func< /// /// The is a delegate to a method that returns if the object /// passed to it matches the conditions defined in the delegate. The elements of the current are individually passed to the delegate. + /// cref="IEnumerable{T}"/> are individually passed to the delegate. /// /// /// This operator executes immediately. @@ -129,7 +129,7 @@ public static int FindLastIndex(this IEnumerable source, Func< /// /// The is a delegate to a method that returns if the object /// passed to it matches the conditions defined in the delegate. The elements of the current are individually passed to the delegate. + /// cref="IEnumerable{T}"/> are individually passed to the delegate. /// /// /// This operator executes immediately. @@ -142,9 +142,7 @@ public static int FindLastIndex(this IEnumerable source, Func< ArgumentOutOfRangeException.ThrowIfNegative(count); if (source.TryGetCollectionCount() is int length) - { index = index.GetOffset(length); - } if (!index.IsFromEnd) { @@ -157,6 +155,7 @@ public static int FindLastIndex(this IEnumerable source, Func< if (predicate(element)) lastIndex = i; + i++; } diff --git a/Source/SuperLinq/FullGroupJoin.cs b/Source/SuperLinq/FullGroupJoin.cs index e6a130b98..71e753a77 100644 --- a/Source/SuperLinq/FullGroupJoin.cs +++ b/Source/SuperLinq/FullGroupJoin.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; // Inspiration & credit: http://stackoverflow.com/a/13503860/6682 public static partial class SuperEnumerable @@ -224,6 +224,7 @@ IEnumerable Core(IEqualityComparer comparer) { if (alookup.Contains(b.Key)) continue; + // We can skip the lookup because we are iterating over keys not found in the first sequence yield return resultSelector(b.Key, [], b); } diff --git a/Source/SuperLinq/GetShortestPath.A-Star.cs b/Source/SuperLinq/GetShortestPath.A-Star.cs index bdb69a48c..6f0362fd3 100644 --- a/Source/SuperLinq/GetShortestPath.A-Star.cs +++ b/Source/SuperLinq/GetShortestPath.A-Star.cs @@ -352,7 +352,8 @@ public partial class SuperEnumerable if (!queue.TryDequeue(out current, out from)) ThrowHelper.ThrowInvalidOperationException("Unable to find path to 'end'."); - } while (true); + } + while (true); return Generate(end, x => totalCost[x].parent!) .TakeUntil(x => stateComparer.Equals(x, start)) diff --git a/Source/SuperLinq/GetShortestPath.Dijkstra.cs b/Source/SuperLinq/GetShortestPath.Dijkstra.cs index 7006e39de..13db279ea 100644 --- a/Source/SuperLinq/GetShortestPath.Dijkstra.cs +++ b/Source/SuperLinq/GetShortestPath.Dijkstra.cs @@ -339,7 +339,8 @@ public partial class SuperEnumerable if (!queue.TryDequeue(out current, out from)) ThrowHelper.ThrowInvalidOperationException("Unable to find path to 'end'."); - } while (true); + } + while (true); return Generate(end, x => totalCost[x].parent!) .TakeUntil(x => stateComparer.Equals(x, start)) diff --git a/Source/SuperLinq/GetShortestPathCost.A-Star.cs b/Source/SuperLinq/GetShortestPathCost.A-Star.cs index 9307f1185..a98cdce5b 100644 --- a/Source/SuperLinq/GetShortestPathCost.A-Star.cs +++ b/Source/SuperLinq/GetShortestPathCost.A-Star.cs @@ -343,7 +343,8 @@ public partial class SuperEnumerable if (!queue.TryDequeue(out current, out costs)) ThrowHelper.ThrowInvalidOperationException("Unable to find path to 'end'."); - } while (true); + } + while (true); return costs.traversed; } diff --git a/Source/SuperLinq/GetShortestPathCost.Dijkstra.cs b/Source/SuperLinq/GetShortestPathCost.Dijkstra.cs index d1fd40117..80fafecf3 100644 --- a/Source/SuperLinq/GetShortestPathCost.Dijkstra.cs +++ b/Source/SuperLinq/GetShortestPathCost.Dijkstra.cs @@ -322,7 +322,8 @@ public partial class SuperEnumerable if (!queue.TryDequeue(out current, out cost)) ThrowHelper.ThrowInvalidOperationException("Unable to find path to 'end'."); - } while (true); + } + while (true); return cost; } diff --git a/Source/SuperLinq/GetShortestPaths.cs b/Source/SuperLinq/GetShortestPaths.cs index 88199b5b3..9e080fb28 100644 --- a/Source/SuperLinq/GetShortestPaths.cs +++ b/Source/SuperLinq/GetShortestPaths.cs @@ -170,7 +170,8 @@ public partial class SuperEnumerable if (!totalCost.TryGetValue(s, out _)) queue.EnqueueMinimum(s, (current, p)); } - } while (queue.TryDequeue(out current, out from)); + } + while (queue.TryDequeue(out current, out from)); return totalCost; } diff --git a/Source/SuperLinq/GlobalSuppressions.cs b/Source/SuperLinq/GlobalSuppressions.cs index 6dd71ac62..b1ebcecfe 100644 --- a/Source/SuperLinq/GlobalSuppressions.cs +++ b/Source/SuperLinq/GlobalSuppressions.cs @@ -1,9 +1,22 @@ -// This file is used by Code Analysis to maintain SuppressMessage +// This file is used by Code Analysis to maintain SuppressMessage // attributes that are applied to this project. // Project-level suppressions either have no target or are given // a specific target and scoped to a namespace, type, member, etc. using System.Diagnostics.CodeAnalysis; -[assembly: SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix", Justification = "PriorityQueue is the proper name for this Data Structure", Scope = "type", Target = "~T:SuperLinq.Collections.UpdatablePriorityQueue`2")] -[assembly: SuppressMessage("Design", "CA1010:Generic interface should also be implemented", Justification = "IReadOnlyCollection is preferred over ICollection", Scope = "type", Target = "~T:SuperLinq.Collections.UpdatablePriorityQueue`2.UnorderedItemsCollection")] +[assembly: SuppressMessage( + "Naming", + "CA1711:Identifiers should not have incorrect suffix", + Justification = "PriorityQueue is the proper name for this Data Structure", + Scope = "type", + Target = "~T:SuperLinq.Collections.UpdatablePriorityQueue`2" +)] + +[assembly: SuppressMessage( + "Design", + "CA1010:Generic interface should also be implemented", + Justification = "IReadOnlyCollection is preferred over ICollection", + Scope = "type", + Target = "~T:SuperLinq.Collections.UpdatablePriorityQueue`2.UnorderedItemsCollection" +)] diff --git a/Source/SuperLinq/GroupAdjacent.cs b/Source/SuperLinq/GroupAdjacent.cs index 2fc2e5482..dd809cbb6 100644 --- a/Source/SuperLinq/GroupAdjacent.cs +++ b/Source/SuperLinq/GroupAdjacent.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections; namespace SuperLinq; @@ -304,7 +304,7 @@ private static IEnumerable GroupAdjacentImpl() { elementSelector(iterator.Current), }; + var members = new List() { elementSelector(iterator.Current) }; while (iterator.MoveNext()) { diff --git a/Source/SuperLinq/Index.cs b/Source/SuperLinq/Index.cs index b5eff15a7..5210bf532 100644 --- a/Source/SuperLinq/Index.cs +++ b/Source/SuperLinq/Index.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { @@ -98,9 +98,7 @@ int startIndex { var cnt = (uint)Count; for (var i = 0; i < cnt; i++) - { yield return (startIndex + i, source[i]); - } } protected override (int index, T item) ElementAt(int index) diff --git a/Source/SuperLinq/Insert.cs b/Source/SuperLinq/Insert.cs index a3bf7a223..3a70eb7c8 100644 --- a/Source/SuperLinq/Insert.cs +++ b/Source/SuperLinq/Insert.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { @@ -88,9 +88,13 @@ public static IEnumerable Insert(this IEnumerable first, IEnumerable if (first.TryGetCollectionCount() is int && second.TryGetCollectionCount() is int) return new InsertCollectionIterator(first, second, index); - return !index.IsFromEnd ? InsertCore(first, second, index.Value) : - index.Value == 0 ? first.Concat(second) : - FromEndCore(first, second, index.Value); + if (!index.IsFromEnd) + return InsertCore(first, second, index.Value); + + if (index.Value == 0) + return first.Concat(second); + + return FromEndCore(first, second, index.Value); static IEnumerable FromEndCore(IEnumerable first, IEnumerable second, int index) { @@ -257,9 +261,13 @@ protected override T ElementAt(int index) ArgumentOutOfRangeException.ThrowIfNegative(idx); ArgumentOutOfRangeException.ThrowIfGreaterThan(idx, _first.Count); - return index < idx ? _first[index] : - index < idx + _second.Count ? _second[index - idx] : - _first[index - _second.Count]; + if (index < idx) + return _first[index]; + + if (index < idx + _second.Count) + return _second[index - idx]; + + return _first[index - _second.Count]; } } } diff --git a/Source/SuperLinq/Interleave.cs b/Source/SuperLinq/Interleave.cs index b60d9d472..24b4c81e1 100644 --- a/Source/SuperLinq/Interleave.cs +++ b/Source/SuperLinq/Interleave.cs @@ -1,4 +1,4 @@ -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; namespace SuperLinq; @@ -81,9 +81,7 @@ private static IEnumerable InterleaveCore(IEnumerable> sour while (list.Any()) { for (var i = 0; list.MoveNext(i); i++) - { yield return list.Current(i); - } } } diff --git a/Source/SuperLinq/Join.HashJoin.cs b/Source/SuperLinq/Join.HashJoin.cs index b27f04b37..3a9d6f47e 100644 --- a/Source/SuperLinq/Join.HashJoin.cs +++ b/Source/SuperLinq/Join.HashJoin.cs @@ -648,6 +648,7 @@ private static IEnumerable JoinHash( { if (leftResultSelector is not null) yield return leftResultSelector(l); + continue; } diff --git a/Source/SuperLinq/Join.MergeJoin.cs b/Source/SuperLinq/Join.MergeJoin.cs index 7e49c54f3..1b0a128c6 100644 --- a/Source/SuperLinq/Join.MergeJoin.cs +++ b/Source/SuperLinq/Join.MergeJoin.cs @@ -643,18 +643,18 @@ private static IEnumerable JoinMerge( Func? leftResultSelector, Func? rightResultSelector, Func bothResultSelector, - IComparer? comparer = null) + IComparer? comparer = null + ) { - ArgumentNullException.ThrowIfNull(left); - ArgumentNullException.ThrowIfNull(right); - ArgumentNullException.ThrowIfNull(leftKeySelector); - ArgumentNullException.ThrowIfNull(rightKeySelector); - ArgumentNullException.ThrowIfNull(bothResultSelector); - comparer ??= Comparer.Default; - using var e1 = left.GroupAdjacent(leftKeySelector, new ComparerEqualityComparer(comparer)).GetEnumerator(); - using var e2 = right.GroupAdjacent(rightKeySelector, new ComparerEqualityComparer(comparer)).GetEnumerator(); + using var e1 = left + .GroupAdjacent(leftKeySelector, new ComparerEqualityComparer(comparer)) + .GetEnumerator(); + + using var e2 = right + .GroupAdjacent(rightKeySelector, new ComparerEqualityComparer(comparer)) + .GetEnumerator(); var gotLeft = e1.MoveNext(); var gotRight = e2.MoveNext(); @@ -704,7 +704,8 @@ private static IEnumerable JoinMerge( { foreach (var e in e1.Current) yield return leftResultSelector(e); - } while (e1.MoveNext()); + } + while (e1.MoveNext()); yield break; } @@ -714,8 +715,8 @@ private static IEnumerable JoinMerge( { foreach (var e in e2.Current) yield return rightResultSelector(e); - } while (e2.MoveNext()); - yield break; + } + while (e2.MoveNext()); } } } diff --git a/Source/SuperLinq/KeyValuePairEqualityComparer.cs b/Source/SuperLinq/KeyValuePairEqualityComparer.cs index ca0ce5b9e..5f2cd97c6 100644 --- a/Source/SuperLinq/KeyValuePairEqualityComparer.cs +++ b/Source/SuperLinq/KeyValuePairEqualityComparer.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; /// /// A utility class to easily compose a custom for - /// with a direction of and a count of 1. + /// with a direction of and a count of 1. /// /// /// This method is implemented by using deferred execution. However, will be consumed - /// in it's entirety immediately when first element of the returned sequence is consumed. + /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// public static IEnumerable MaxItems(this IEnumerable source) @@ -53,11 +53,11 @@ public static IEnumerable MaxItems(this IEnumerable source) /// /// /// This operator is a shortcut for with a count of 1. + /// OrderByDirection)"/> with a count of 1. /// /// /// This method is implemented by using deferred execution. However, will be consumed - /// in it's entirety immediately when first element of the returned sequence is consumed. + /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// public static IEnumerable MaxItems(this IEnumerable source, IComparer? comparer) @@ -90,11 +90,11 @@ public static IEnumerable MaxItems(this IEnumerable source, IComparer /// This operator is a shortcut for with a direction of and a count of 1. + /// cref="OrderByDirection.Descending"/> and a count of 1. /// /// /// This method is implemented by using deferred execution. However, will be consumed - /// in it's entirety immediately when first element of the returned sequence is consumed. + /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// public static IEnumerable MaxItemsBy(this IEnumerable source, Func keySelector) @@ -127,11 +127,11 @@ public static IEnumerable MaxItemsBy(this IEnumerable /// This operator is a shortcut for with a direction of and a count of 1. + /// cref="OrderByDirection.Descending"/> and a count of 1. /// /// /// This method is implemented by using deferred execution. However, will be consumed - /// in it's entirety immediately when first element of the returned sequence is consumed. + /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// public static IEnumerable MaxByWithTies(this IEnumerable source, Func keySelector) @@ -167,14 +167,18 @@ public static IEnumerable MaxByWithTies(this IEnumerable /// /// This operator is a shortcut for with a direction of and a count of 1. + /// cref="OrderByDirection.Descending"/> and a count of 1. /// /// /// This method is implemented by using deferred execution. However, will be consumed - /// in it's entirety immediately when first element of the returned sequence is consumed. + /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// - public static IEnumerable MaxItemsBy(this IEnumerable source, Func keySelector, IComparer? comparer) + public static IEnumerable MaxItemsBy( + this IEnumerable source, + Func keySelector, + IComparer? comparer + ) { return source.DensePartialSortBy(1, keySelector, comparer, OrderByDirection.Descending); } @@ -207,14 +211,18 @@ public static IEnumerable MaxItemsBy(this IEnumerable /// This operator is a shortcut for with a direction of and a count of 1. + /// cref="OrderByDirection.Descending"/> and a count of 1. /// /// /// This method is implemented by using deferred execution. However, will be consumed - /// in it's entirety immediately when first element of the returned sequence is consumed. + /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// - public static IEnumerable MaxByWithTies(this IEnumerable source, Func keySelector, IComparer? comparer) + public static IEnumerable MaxByWithTies( + this IEnumerable source, + Func keySelector, + IComparer? comparer + ) { return source.DensePartialSortBy(1, keySelector, comparer, OrderByDirection.Descending); } diff --git a/Source/SuperLinq/Memoize.cs b/Source/SuperLinq/Memoize.cs index 6031f5cf7..368f99957 100644 --- a/Source/SuperLinq/Memoize.cs +++ b/Source/SuperLinq/Memoize.cs @@ -145,6 +145,7 @@ private IEnumerator GetEnumeratorImpl() { if (_disposed) ThrowHelper.ThrowObjectDisposedException>(); + if (!_initialized || buffer != _buffer) { @@ -236,9 +237,10 @@ public int Count get { var h = _state; - if (h.State != State.Initialized) - return 0; - return h.Buffer!.Length; + + return h.State != State.Initialized + ? 0 + : h.Buffer!.Length; } } @@ -261,16 +263,21 @@ public void Reset() var res = Interlocked.CompareExchange(ref _state, new(State.Uninitialized), h); if (res != h) continue; + return; } case State.Disposed: + { ThrowHelper.ThrowObjectDisposedException>(); break; + } default: + { ThrowHelper.ThrowUnreachableException(); return; + } } } } @@ -294,9 +301,12 @@ private T[] InitializeBuffer() case State.Uninitialized: { var tmp = new CmbHelper(State.Initializing); + // are we first? var res = Interlocked.CompareExchange(ref _state, tmp, h); - if (res != h) continue; + if (res != h) + continue; + h = tmp; // we should be only ones inside here @@ -318,8 +328,10 @@ private T[] InitializeBuffer() // we've got an array, set it res = Interlocked.CompareExchange(ref _state, new(State.Initialized, Buffer: array), tmp); + // only way this could happen is dispose, so loop again to trigger dispose handling - if (res != tmp) continue; + if (res != tmp) + continue; // we've got the array, hand it out. return array; @@ -329,20 +341,28 @@ private T[] InitializeBuffer() continue; case State.Initialized: + { Assert.NotNull(h.Buffer); return h.Buffer; + } case State.Disposed: + { ThrowHelper.ThrowObjectDisposedException>(); break; + } case State.Error: + { h.Exception!.Throw(); break; + } default: + { ThrowHelper.ThrowUnreachableException(); return default!; + } } } } @@ -380,12 +400,14 @@ ICollection source ) : IBuffer { private ICollection? _source = source; + private ICollection Source { get { if (_source is null) ThrowHelper.ThrowObjectDisposedException>(); + return _source; } } diff --git a/Source/SuperLinq/MinItems.cs b/Source/SuperLinq/MinItems.cs index 87aae43e4..f9f9a2f41 100644 --- a/Source/SuperLinq/MinItems.cs +++ b/Source/SuperLinq/MinItems.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { @@ -20,11 +20,11 @@ public static partial class SuperEnumerable /// /// /// This operator is a shortcut for - /// with a direction of and a count of 1. + /// with a direction of and a count of 1. /// /// /// This method is implemented by using deferred execution. However, will be consumed - /// in it's entirety immediately when first element of the returned sequence is consumed. + /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// public static IEnumerable MinItems(this IEnumerable source) @@ -53,11 +53,11 @@ public static IEnumerable MinItems(this IEnumerable source) /// /// /// This operator is a shortcut for with a count of 1. + /// OrderByDirection)"/> with a count of 1. /// /// /// This method is implemented by using deferred execution. However, will be consumed - /// in it's entirety immediately when first element of the returned sequence is consumed. + /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// public static IEnumerable MinItems(this IEnumerable source, IComparer? comparer) @@ -90,11 +90,11 @@ public static IEnumerable MinItems(this IEnumerable source, IComparer /// This operator is a shortcut for with a direction of and a count of 1. + /// cref="OrderByDirection.Ascending"/> and a count of 1. /// /// /// This method is implemented by using deferred execution. However, will be consumed - /// in it's entirety immediately when first element of the returned sequence is consumed. + /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// public static IEnumerable MinItemsBy(this IEnumerable source, Func keySelector) @@ -127,11 +127,11 @@ public static IEnumerable MinItemsBy(this IEnumerable /// This operator is a shortcut for with a direction of and a count of 1. + /// cref="OrderByDirection.Ascending"/> and a count of 1. /// /// /// This method is implemented by using deferred execution. However, will be consumed - /// in it's entirety immediately when first element of the returned sequence is consumed. + /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// public static IEnumerable MinByWithTies(this IEnumerable source, Func keySelector) @@ -167,14 +167,18 @@ public static IEnumerable MinByWithTies(this IEnumerable /// /// This operator is a shortcut for with a direction of and a count of 1. + /// cref="OrderByDirection.Ascending"/> and a count of 1. /// /// /// This method is implemented by using deferred execution. However, will be consumed - /// in it's entirety immediately when first element of the returned sequence is consumed. + /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// - public static IEnumerable MinItemsBy(this IEnumerable source, Func keySelector, IComparer? comparer) + public static IEnumerable MinItemsBy( + this IEnumerable source, + Func keySelector, + IComparer? comparer + ) { return source.DensePartialSortBy(1, keySelector, comparer, OrderByDirection.Ascending); } @@ -207,14 +211,18 @@ public static IEnumerable MinItemsBy(this IEnumerable /// This operator is a shortcut for with a direction of and a count of 1. + /// cref="OrderByDirection.Ascending"/> and a count of 1. /// /// /// This method is implemented by using deferred execution. However, will be consumed - /// in it's entirety immediately when first element of the returned sequence is consumed. + /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// - public static IEnumerable MinByWithTies(this IEnumerable source, Func keySelector, IComparer? comparer) + public static IEnumerable MinByWithTies( + this IEnumerable source, + Func keySelector, + IComparer? comparer + ) { return source.DensePartialSortBy(1, keySelector, comparer, OrderByDirection.Ascending); } diff --git a/Source/SuperLinq/OnErrorResumeNext.cs b/Source/SuperLinq/OnErrorResumeNext.cs index 85f667a87..f8226d812 100644 --- a/Source/SuperLinq/OnErrorResumeNext.cs +++ b/Source/SuperLinq/OnErrorResumeNext.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { @@ -34,7 +34,7 @@ public static IEnumerable OnErrorResumeNext(this IEnumerable diff --git a/Source/SuperLinq/OrderBy.cs b/Source/SuperLinq/OrderBy.cs index 4161a19e0..51ffad014 100644 --- a/Source/SuperLinq/OrderBy.cs +++ b/Source/SuperLinq/OrderBy.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { @@ -29,7 +29,7 @@ public static partial class SuperEnumerable /// /// /// This method is implemented by using deferred execution. However, will be consumed - /// in it's entirety immediately when first element of the returned sequence is consumed. + /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// public static IOrderedEnumerable OrderBy(this IEnumerable source, Func keySelector, OrderByDirection direction) @@ -67,10 +67,15 @@ public static IOrderedEnumerable OrderBy(this IEnumerable source, /// /// /// This method is implemented by using deferred execution. However, will be consumed - /// in it's entirety immediately when first element of the returned sequence is consumed. + /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// - public static IOrderedEnumerable OrderBy(this IEnumerable source, Func keySelector, IComparer? comparer, OrderByDirection direction) + public static IOrderedEnumerable OrderBy( + this IEnumerable source, + Func keySelector, + IComparer? comparer, + OrderByDirection direction + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(keySelector); @@ -106,10 +111,14 @@ public static IOrderedEnumerable OrderBy(this IEnumerable source, /// /// /// This method is implemented by using deferred execution. However, will be consumed - /// in it's entirety immediately when first element of the returned sequence is consumed. + /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// - public static IOrderedEnumerable ThenBy(this IOrderedEnumerable source, Func keySelector, OrderByDirection direction) + public static IOrderedEnumerable ThenBy( + this IOrderedEnumerable source, + Func keySelector, + OrderByDirection direction + ) { return ThenBy(source, keySelector, comparer: null, direction); } @@ -144,10 +153,15 @@ public static IOrderedEnumerable ThenBy(this IOrderedEnumerable s /// /// /// This method is implemented by using deferred execution. However, will be consumed - /// in it's entirety immediately when first element of the returned sequence is consumed. + /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// - public static IOrderedEnumerable ThenBy(this IOrderedEnumerable source, Func keySelector, IComparer? comparer, OrderByDirection direction) + public static IOrderedEnumerable ThenBy( + this IOrderedEnumerable source, + Func keySelector, + IComparer? comparer, + OrderByDirection direction + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(keySelector); diff --git a/Source/SuperLinq/OrderByDirection.cs b/Source/SuperLinq/OrderByDirection.cs index 72b179dbe..28b0eb1c5 100644 --- a/Source/SuperLinq/OrderByDirection.cs +++ b/Source/SuperLinq/OrderByDirection.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; /// /// Enumeration that defines values representing valid ordering directions for a sequence. @@ -9,6 +9,7 @@ public enum OrderByDirection /// Elements are ordered by increasing value /// Ascending = 0, + /// /// Elements are ordered by decreasing value /// diff --git a/Source/SuperLinq/PadStart.cs b/Source/SuperLinq/PadStart.cs index 8792d8041..2162f6a3c 100644 --- a/Source/SuperLinq/PadStart.cs +++ b/Source/SuperLinq/PadStart.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { @@ -157,6 +157,7 @@ protected override IEnumerable GetEnumerable() var cnt = width - source.GetCollectionCount(); for (var i = 0; i < cnt; i++) yield return paddingSelector(i); + foreach (var item in source) yield return item; } @@ -188,6 +189,7 @@ protected override IEnumerable GetEnumerable() var cnt = (uint)source.Count; for (var i = 0; i < width - cnt; i++) yield return paddingSelector(i); + for (var i = 0; i < cnt; i++) yield return source[i]; } diff --git a/Source/SuperLinq/PartialSort.cs b/Source/SuperLinq/PartialSort.cs index ad4581361..292033c4e 100644 --- a/Source/SuperLinq/PartialSort.cs +++ b/Source/SuperLinq/PartialSort.cs @@ -211,12 +211,12 @@ static IEnumerable Core(IEnumerable source, int count, IComparer compar /// /// The source sequence. /// - /// - /// A function to extract a key from an element. - /// /// /// Number of (maximum) elements to return. /// + /// + /// A function to extract a key from an element. + /// /// /// A sequence containing at most top elements from source, in ascending order of their /// keys. @@ -256,12 +256,12 @@ public static IEnumerable PartialSortBy( /// /// The source sequence. /// - /// - /// A function to extract a key from an element. - /// /// /// Number of (maximum) elements to return. /// + /// + /// A function to extract a key from an element. + /// /// /// The direction in which to sort the elements /// @@ -304,12 +304,12 @@ public static IEnumerable PartialSortBy( /// /// The source sequence. /// - /// - /// A function to extract a key from an element. - /// /// /// Number of (maximum) elements to return. /// + /// + /// A function to extract a key from an element. + /// /// /// A to compare elements. /// @@ -354,12 +354,12 @@ public static IEnumerable PartialSortBy( /// /// The source sequence. /// - /// - /// A function to extract a key from an element. - /// /// /// Number of (maximum) elements to return. /// + /// + /// A function to extract a key from an element. + /// /// /// A to compare elements. /// diff --git a/Source/SuperLinq/Permutations.cs b/Source/SuperLinq/Permutations.cs index 451245787..d21ea0813 100644 --- a/Source/SuperLinq/Permutations.cs +++ b/Source/SuperLinq/Permutations.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { @@ -26,7 +26,7 @@ public static partial class SuperEnumerable /// /// /// This method is implemented by using deferred execution. However, will be - /// consumed in it's entirety immediately when first element of the returned sequence is consumed. + /// consumed in it's entirety immediately when first element of the returned sequence is consumed. /// /// /// Each permutation is materialized into a new list. There are N! permutations of a sequence, where N is the @@ -43,7 +43,10 @@ public static IEnumerable> Permutations(this IEnumerable sequence if (sequence.TryGetCollectionCount() is int and > 21) { - ThrowHelper.ThrowArgumentException(nameof(sequence), "Input set is too large to permute properly."); + ThrowHelper.ThrowArgumentException( + nameof(sequence), + "Input set is too large to permute properly." + ); } return Core(sequence); @@ -78,6 +81,7 @@ static T[] PermuteValueSet(int[] permutation, List valueSet) var permutedSet = new T[permutation.Length]; for (var i = 0; i < permutation.Length; i++) permutedSet[i] = valueSet[permutation[i]]; + return permutedSet; } diff --git a/Source/SuperLinq/Publish.cs b/Source/SuperLinq/Publish.cs index 7642a0efe..5eeaf43fb 100644 --- a/Source/SuperLinq/Publish.cs +++ b/Source/SuperLinq/Publish.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections; using System.Runtime.ExceptionServices; namespace SuperLinq; @@ -123,6 +123,7 @@ public IEnumerator GetEnumerator() return (queue, _version); } } + private IEnumerator GetEnumeratorImpl(Queue buffer, int version) { try @@ -134,6 +135,7 @@ private IEnumerator GetEnumeratorImpl(Queue buffer, int version) { if (_disposed) ThrowHelper.ThrowObjectDisposedException>(); + if (!_initialized || version != _version) { diff --git a/Source/SuperLinq/RandomSubset.cs b/Source/SuperLinq/RandomSubset.cs index 6d637b5ae..446a313f5 100644 --- a/Source/SuperLinq/RandomSubset.cs +++ b/Source/SuperLinq/RandomSubset.cs @@ -26,7 +26,7 @@ public static partial class SuperEnumerable /// /// /// This method is implemented by using deferred execution. However, will be consumed - /// in it's entirety immediately when first element of the returned sequence is consumed. + /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// public static IEnumerable RandomSubset(this IEnumerable source, int subsetSize) @@ -61,7 +61,7 @@ public static IEnumerable RandomSubset(this IEnumerable source, int sub /// /// /// This method is implemented by using deferred execution. However, will be consumed - /// in it's entirety immediately when first element of the returned sequence is consumed. + /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// public static IEnumerable RandomSubset(this IEnumerable source, int subsetSize, Random rand) diff --git a/Source/SuperLinq/Repeat.cs b/Source/SuperLinq/Repeat.cs index f5ea47496..5001008b5 100644 --- a/Source/SuperLinq/Repeat.cs +++ b/Source/SuperLinq/Repeat.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public partial class SuperEnumerable { @@ -39,7 +39,7 @@ public static IEnumerable Repeat(TResult value) /// /// This operator uses deferred execution and streams its result. The sequence is /// cached as the returned is enumerated. When has - /// completed, the values from will be returned again indefinitely. + /// completed, the values from will be returned again indefinitely. /// /// /// The cache is maintained separately for each generated from the returned Core(IEnumerable source) /// /// This operator uses deferred execution and streams its result. The sequence is /// cached as the returned is enumerated. When has - /// completed, the values from will be returned again times. + /// completed, the values from will be returned again times. /// /// /// The cache is maintained separately for each generated from the returned throw ReadOnlyException(); } - public IEnumerator GetEnumerator() { yield return item; } + public IEnumerator GetEnumerator() + { + yield return item; + } + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); public int IndexOf(T item) => Contains(item) ? 0 : -1; diff --git a/Source/SuperLinq/ScanRight.cs b/Source/SuperLinq/ScanRight.cs index d6d32db92..9aa836725 100644 --- a/Source/SuperLinq/ScanRight.cs +++ b/Source/SuperLinq/ScanRight.cs @@ -1,4 +1,4 @@ -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; namespace SuperLinq; @@ -110,13 +110,13 @@ public override void CopyTo(T[] array, int arrayIndex) /// /// Source sequence. /// + /// + /// The initial accumulator value. + /// /// /// A right-associative accumulator function to be invoked on each element. Its first argument is the current /// value in the sequence; second argument is the previous accumulator value. /// - /// - /// The initial accumulator value. - /// /// /// The scanned sequence. /// @@ -129,7 +129,11 @@ public override void CopyTo(T[] array, int arrayIndex) /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// - public static IEnumerable ScanRight(this IEnumerable source, TAccumulate seed, Func func) + public static IEnumerable ScanRight( + this IEnumerable source, + TAccumulate seed, + Func func + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(func); diff --git a/Source/SuperLinq/Share.cs b/Source/SuperLinq/Share.cs index f1af74fa4..7a7eaf46d 100644 --- a/Source/SuperLinq/Share.cs +++ b/Source/SuperLinq/Share.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections; using System.Runtime.ExceptionServices; namespace SuperLinq; @@ -110,6 +110,7 @@ private IEnumerator GetEnumeratorImpl() { if (_disposed) ThrowHelper.ThrowObjectDisposedException>(); + if (!_initialized || version != _version) { diff --git a/Source/SuperLinq/Shuffle.cs b/Source/SuperLinq/Shuffle.cs index 9eb29e94f..6879790ac 100644 --- a/Source/SuperLinq/Shuffle.cs +++ b/Source/SuperLinq/Shuffle.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { @@ -20,7 +20,7 @@ public static partial class SuperEnumerable /// /// /// This method is implemented by using deferred execution. However, will be consumed - /// in it's entirety immediately when first element of the returned sequence is consumed. + /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// public static IEnumerable Shuffle(this IEnumerable source) @@ -50,7 +50,7 @@ public static IEnumerable Shuffle(this IEnumerable source) /// /// /// This method is implemented by using deferred execution. However, will be consumed - /// in it's entirety immediately when first element of the returned sequence is consumed. + /// in it's entirety immediately when first element of the returned sequence is consumed. /// /// public static IEnumerable Shuffle(this IEnumerable source, Random rand) diff --git a/Source/SuperLinq/SkipUntil.cs b/Source/SuperLinq/SkipUntil.cs index 750198357..8eafe67b7 100644 --- a/Source/SuperLinq/SkipUntil.cs +++ b/Source/SuperLinq/SkipUntil.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { diff --git a/Source/SuperLinq/SortedMerge.cs b/Source/SuperLinq/SortedMerge.cs index a8495e9f4..b02fc09a9 100644 --- a/Source/SuperLinq/SortedMerge.cs +++ b/Source/SuperLinq/SortedMerge.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { @@ -42,12 +42,12 @@ public static IEnumerable SortedMerge(this IEnumerable /// The primary sequence with which to merge /// - /// - /// A variable argument array of zero or more other sequences to merge with - /// /// /// An to compare elements /// + /// + /// A variable argument array of zero or more other sequences to merge with + /// /// /// or is . /// @@ -62,7 +62,11 @@ public static IEnumerable SortedMerge(this IEnumerable /// - public static IEnumerable SortedMerge(this IEnumerable source, IComparer? comparer, params IEnumerable[] otherSequences) + public static IEnumerable SortedMerge( + this IEnumerable source, + IComparer? comparer, + params IEnumerable[] otherSequences + ) { return SortedMerge(source, OrderByDirection.Ascending, comparer, otherSequences); } @@ -76,12 +80,12 @@ public static IEnumerable SortedMerge(this IEnumerable /// The primary sequence with which to merge /// - /// - /// A variable argument array of zero or more other sequences to merge with - /// /// /// A direction in which to order the elements (ascending, descending) /// + /// + /// A variable argument array of zero or more other sequences to merge with + /// /// /// or is . /// @@ -96,7 +100,11 @@ public static IEnumerable SortedMerge(this IEnumerable /// - public static IEnumerable SortedMerge(this IEnumerable source, OrderByDirection direction, params IEnumerable[] otherSequences) + public static IEnumerable SortedMerge( + this IEnumerable source, + OrderByDirection direction, + params IEnumerable[] otherSequences + ) { return SortedMerge(source, direction, comparer: null, otherSequences); } @@ -110,15 +118,15 @@ public static IEnumerable SortedMerge(this IEnumerable /// The primary sequence with which to merge /// - /// - /// A variable argument array of zero or more other sequences to merge with - /// /// /// A direction in which to order the elements (ascending, descending) /// /// /// An to compare elements /// + /// + /// A variable argument array of zero or more other sequences to merge with + /// /// /// or is . /// @@ -133,7 +141,12 @@ public static IEnumerable SortedMerge(this IEnumerable /// - public static IEnumerable SortedMerge(this IEnumerable source, OrderByDirection direction, IComparer? comparer, params IEnumerable[] otherSequences) + public static IEnumerable SortedMerge( + this IEnumerable source, + OrderByDirection direction, + IComparer? comparer, + params IEnumerable[] otherSequences + ) { return SortedMergeBy(source, Identity, direction, comparer, otherSequences); } @@ -173,7 +186,11 @@ public static IEnumerable SortedMerge(this IEnumerable /// - public static IEnumerable SortedMergeBy(this IEnumerable source, Func keySelector, params IEnumerable[] otherSequences) + public static IEnumerable SortedMergeBy( + this IEnumerable source, + Func keySelector, + params IEnumerable[] otherSequences + ) { return SortedMergeBy(source, keySelector, OrderByDirection.Ascending, comparer: null, otherSequences); } @@ -194,12 +211,12 @@ public static IEnumerable SortedMergeBy(this IEnumerable /// /// A key selector function /// - /// - /// A variable argument array of zero or more other sequences to merge with - /// /// /// An to compare keys /// + /// + /// A variable argument array of zero or more other sequences to merge with + /// /// /// , or is . @@ -216,7 +233,12 @@ public static IEnumerable SortedMergeBy(this IEnumerable /// This method uses deferred execution and streams its results. /// /// - public static IEnumerable SortedMergeBy(this IEnumerable source, Func keySelector, IComparer? comparer, params IEnumerable[] otherSequences) + public static IEnumerable SortedMergeBy( + this IEnumerable source, + Func keySelector, + IComparer? comparer, + params IEnumerable[] otherSequences + ) { return SortedMergeBy(source, keySelector, OrderByDirection.Ascending, comparer, otherSequences); } @@ -237,12 +259,12 @@ public static IEnumerable SortedMergeBy(this IEnumerable /// /// A key selector function /// - /// - /// A variable argument array of zero or more other sequences to merge with - /// /// /// A direction in which to order the elements (ascending, descending) /// + /// + /// A variable argument array of zero or more other sequences to merge with + /// /// /// , or is . @@ -259,7 +281,11 @@ public static IEnumerable SortedMergeBy(this IEnumerable /// This method uses deferred execution and streams its results. /// /// - public static IEnumerable SortedMergeBy(this IEnumerable source, Func keySelector, OrderByDirection direction, params IEnumerable[] otherSequences) + public static IEnumerable SortedMergeBy( + this IEnumerable source, + Func keySelector, + OrderByDirection direction, + params IEnumerable[] otherSequences) { return SortedMergeBy(source, keySelector, direction, comparer: null, otherSequences); } @@ -280,15 +306,15 @@ public static IEnumerable SortedMergeBy(this IEnumerable /// /// A key selector function /// - /// - /// A variable argument array of zero or more other sequences to merge with - /// /// /// A direction in which to order the elements (ascending, descending) /// /// /// An to compare keys /// + /// + /// A variable argument array of zero or more other sequences to merge with + /// /// /// , or is . @@ -305,7 +331,12 @@ public static IEnumerable SortedMergeBy(this IEnumerable /// This method uses deferred execution and streams its results. /// /// - public static IEnumerable SortedMergeBy(this IEnumerable source, Func keySelector, OrderByDirection direction, IComparer? comparer, params IEnumerable[] otherSequences) + public static IEnumerable SortedMergeBy( + this IEnumerable source, + Func keySelector, + OrderByDirection direction, + IComparer? comparer, + params IEnumerable[] otherSequences) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(keySelector); diff --git a/Source/SuperLinq/Split.cs b/Source/SuperLinq/Split.cs index c74cc0047..d853a061a 100644 --- a/Source/SuperLinq/Split.cs +++ b/Source/SuperLinq/Split.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { @@ -29,7 +29,8 @@ public static partial class SuperEnumerable /// public static IEnumerable> Split( this IEnumerable source, - TSource separator) + TSource separator + ) { return Split(source, separator, count: int.MaxValue); } @@ -67,7 +68,9 @@ public static IEnumerable> Split( /// public static IEnumerable> Split( this IEnumerable source, - TSource separator, int count) + TSource separator, + int count + ) { return Split(source, separator, count, Identity); } @@ -106,7 +109,8 @@ public static IEnumerable> Split( public static IEnumerable Split( this IEnumerable source, TSource separator, - Func, TResult> resultSelector) + Func, TResult> resultSelector + ) { return Split(source, separator, count: int.MaxValue, resultSelector); } @@ -152,7 +156,8 @@ public static IEnumerable Split( public static IEnumerable Split( this IEnumerable source, TSource separator, int count, - Func, TResult> resultSelector) + Func, TResult> resultSelector + ) { return Split(source, separator, comparer: null, count, resultSelector); } @@ -187,7 +192,9 @@ public static IEnumerable Split( /// public static IEnumerable> Split( this IEnumerable source, - TSource separator, IEqualityComparer? comparer) + TSource separator, + IEqualityComparer? comparer + ) { return Split(source, separator, comparer, count: int.MaxValue); } @@ -229,7 +236,10 @@ public static IEnumerable> Split( /// public static IEnumerable> Split( this IEnumerable source, - TSource separator, IEqualityComparer? comparer, int count) + TSource separator, + IEqualityComparer? comparer, + int count + ) { return Split(source, separator, comparer, count, Identity); } @@ -272,7 +282,8 @@ public static IEnumerable> Split( public static IEnumerable Split( this IEnumerable source, TSource separator, IEqualityComparer comparer, - Func, TResult> resultSelector) + Func, TResult> resultSelector + ) { return Split(source, separator, comparer, count: int.MaxValue, resultSelector); } @@ -321,7 +332,8 @@ public static IEnumerable Split( public static IEnumerable Split( this IEnumerable source, TSource separator, IEqualityComparer? comparer, int count, - Func, TResult> resultSelector) + Func, TResult> resultSelector + ) { ArgumentNullException.ThrowIfNull(source); ArgumentOutOfRangeException.ThrowIfNegativeOrZero(count); @@ -358,7 +370,8 @@ public static IEnumerable Split( /// public static IEnumerable> Split( this IEnumerable source, - Func separatorFunc) + Func separatorFunc + ) { return Split(source, separatorFunc, count: int.MaxValue); } @@ -396,7 +409,9 @@ public static IEnumerable> Split( /// public static IEnumerable> Split( this IEnumerable source, - Func separatorFunc, int count) + Func separatorFunc, + int count + ) { return Split(source, separatorFunc, count, Identity); } @@ -437,7 +452,8 @@ public static IEnumerable> Split( public static IEnumerable Split( this IEnumerable source, Func separatorFunc, - Func, TResult> resultSelector) + Func, TResult> resultSelector + ) { return Split(source, separatorFunc, count: int.MaxValue, resultSelector); } @@ -483,8 +499,10 @@ public static IEnumerable Split( /// public static IEnumerable Split( this IEnumerable source, - Func separatorFunc, int count, - Func, TResult> resultSelector) + Func separatorFunc, + int count, + Func, TResult> resultSelector + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(separatorFunc); @@ -493,7 +511,12 @@ public static IEnumerable Split( return Core(source, separatorFunc, count, resultSelector); - static IEnumerable Core(IEnumerable source, Func separatorFunc, int count, Func, TResult> resultSelector) + static IEnumerable Core( + IEnumerable source, + Func separatorFunc, + int count, + Func, TResult> resultSelector + ) { var items = new List(); diff --git a/Source/SuperLinq/StartsWith.cs b/Source/SuperLinq/StartsWith.cs index 904a31627..dd59ddd35 100644 --- a/Source/SuperLinq/StartsWith.cs +++ b/Source/SuperLinq/StartsWith.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { @@ -71,9 +71,9 @@ public static bool StartsWith(this IEnumerable first, IEnumerable secon ArgumentNullException.ThrowIfNull(first); ArgumentNullException.ThrowIfNull(second); - if (first.TryGetCollectionCount() is int firstCount && - second.TryGetCollectionCount() is int secondCount && - secondCount > firstCount) + if (first.TryGetCollectionCount() is int firstCount + && second.TryGetCollectionCount() is int secondCount + && secondCount > firstCount) { return false; } diff --git a/Source/SuperLinq/Subsets.cs b/Source/SuperLinq/Subsets.cs index 101fd5d28..a3f16a9fd 100644 --- a/Source/SuperLinq/Subsets.cs +++ b/Source/SuperLinq/Subsets.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { @@ -27,7 +27,7 @@ public static partial class SuperEnumerable /// /// /// This method is implemented by using deferred execution. However, will be - /// consumed in it's entirety immediately when first element of the returned sequence is consumed. + /// consumed in it's entirety immediately when first element of the returned sequence is consumed. /// /// public static IEnumerable> Subsets(this IEnumerable sequence) @@ -146,6 +146,7 @@ private static IEnumerable> Subsets(List set, int subsetSize) subset[i] = set[indices[i] - 1]; yield return subset; + } while (indices[0] != setSize - subsetSize + 1); } diff --git a/Source/SuperLinq/SuperEnumerable.cs b/Source/SuperLinq/SuperEnumerable.cs index 5a173383f..ab19ad174 100644 --- a/Source/SuperLinq/SuperEnumerable.cs +++ b/Source/SuperLinq/SuperEnumerable.cs @@ -1,4 +1,4 @@ -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; namespace SuperLinq; @@ -51,6 +51,7 @@ internal static int GetCollectionCount(this IEnumerable source) #if NET6_0_OR_GREATER if (!source.TryGetNonEnumeratedCount(out var count)) ThrowHelper.ThrowInvalidOperationException("Expected valid non-enumerated count."); + return count; #else return source switch diff --git a/Source/SuperLinq/TagFirstLast.cs b/Source/SuperLinq/TagFirstLast.cs index 2274cb817..9f7313e7d 100644 --- a/Source/SuperLinq/TagFirstLast.cs +++ b/Source/SuperLinq/TagFirstLast.cs @@ -55,7 +55,10 @@ public static partial class SuperEnumerable /// This operator uses deferred execution and streams its results. /// /// - public static IEnumerable TagFirstLast(this IEnumerable source, Func resultSelector) + public static IEnumerable TagFirstLast( + this IEnumerable source, + Func resultSelector + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(resultSelector); @@ -99,6 +102,7 @@ protected override IEnumerable GetEnumerable() { if (source.Count == 1) yield return resultSelector(source[0], true, true); + yield break; } diff --git a/Source/SuperLinq/Take.cs b/Source/SuperLinq/Take.cs index 3d2f60cb8..378f896df 100644 --- a/Source/SuperLinq/Take.cs +++ b/Source/SuperLinq/Take.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. namespace SuperLinq; @@ -47,9 +47,7 @@ public static IEnumerable Take(IEnumerable source, Ra if (start.IsFromEnd) { if (start.Value == 0 || (end.IsFromEnd && end.Value >= start.Value)) - { return []; - } } else if (!end.IsFromEnd) { @@ -67,14 +65,10 @@ private static IEnumerable TakeRangeIterator(IEnumerable TakeRangeFromEndIterator(IEnumerabl if (startIndex < endIndex) { foreach (var element in TakeRangeIterator(source, startIndex, endIndex)) - { yield return element; - } } yield break; @@ -114,9 +106,7 @@ private static IEnumerable TakeRangeFromEndIterator(IEnumerabl using (var e = source.GetEnumerator()) { if (!e.MoveNext()) - { yield break; - } queue = new Queue(); queue.Enqueue(e.Current); @@ -129,7 +119,10 @@ private static IEnumerable TakeRangeFromEndIterator(IEnumerabl _ = queue.Dequeue(); queue.Enqueue(e.Current); - checked { ++count; } + checked + { + ++count; + } } } @@ -137,9 +130,7 @@ private static IEnumerable TakeRangeFromEndIterator(IEnumerabl var endIndex = Math.Min(count, end.GetOffset(count)); for (var rangeIndex = startIndex; rangeIndex < endIndex; rangeIndex++) - { yield return queue.Dequeue(); - } } else { @@ -150,9 +141,7 @@ private static IEnumerable TakeRangeFromEndIterator(IEnumerabl var endCount = end.Value; count = 0; while (count < startCount && e.MoveNext()) - { ++count; - } if (count == startCount) { diff --git a/Source/SuperLinq/Throw.cs b/Source/SuperLinq/Throw.cs index d48e0bbd8..3ae0af284 100644 --- a/Source/SuperLinq/Throw.cs +++ b/Source/SuperLinq/Throw.cs @@ -19,7 +19,7 @@ public static partial class SuperEnumerable /// /// /// - /// The provided value () will be thrown when the first element is enumerated. + /// The provided value () will be thrown when the first element is enumerated. /// /// /// If the returned is enumerated multiple times, the same value will be thrown diff --git a/Source/SuperLinq/ToDataTable.cs b/Source/SuperLinq/ToDataTable.cs index d71eb8ea9..d7cb267e9 100644 --- a/Source/SuperLinq/ToDataTable.cs +++ b/Source/SuperLinq/ToDataTable.cs @@ -173,8 +173,7 @@ Expression>[] expressions if (expressions.Length == 0) { return typeof(T).GetMembers(BindingFlags.Public | BindingFlags.Instance) - .Where(m => - m.MemberType == MemberTypes.Field + .Where(m => m.MemberType == MemberTypes.Field || (m is PropertyInfo { CanRead: true } p && p.GetIndexParameters().Length == 0) ); } @@ -187,14 +186,14 @@ Expression>[] expressions // If it's a field access, boxing was used, we need the field if (body.NodeType is ExpressionType.Convert or ExpressionType.ConvertChecked) - { body = ((UnaryExpression)body).Operand; - } // Check if the member expression is valid and is a "first level" // member access e.g. not a.b.c - if (body is not MemberExpression me - || me.Expression?.NodeType != ExpressionType.Parameter) + if ( + body is not MemberExpression me + || me.Expression?.NodeType != ExpressionType.Parameter + ) { return ThrowHelper.ThrowArgumentException(nameof(lambda), $"Illegal expression: {lambda}"); } @@ -259,10 +258,20 @@ private static MemberInfo[] BuildOrBindSchema(DataTable table, MemberInfo[] memb var column = info.Column; if (column is null) - ThrowHelper.ThrowArgumentException(nameof(table), $"Column named '{member.Name}' is missing."); + { + ThrowHelper.ThrowArgumentException( + nameof(table), + $"Column named '{member.Name}' is missing." + ); + } if (info.Type != column.DataType) - ThrowHelper.ThrowArgumentException(nameof(table), $"Column named '{member.Name}' has wrong data type. It should be {info.Type} when it is {column.DataType}."); + { + ThrowHelper.ThrowArgumentException( + nameof(table), + $"Column named '{member.Name}' has wrong data type. It should be {info.Type} when it is {column.DataType}." + ); + } members[column.Ordinal] = member; } diff --git a/Source/SuperLinq/ToDelimitedString.cs b/Source/SuperLinq/ToDelimitedString.cs index 4295c15b6..6c1af319c 100644 --- a/Source/SuperLinq/ToDelimitedString.cs +++ b/Source/SuperLinq/ToDelimitedString.cs @@ -1,4 +1,4 @@ -using System.Text; +using System.Text; namespace SuperLinq; @@ -40,7 +40,9 @@ private static string ToDelimitedStringImpl(IEnumerable source, string del foreach (var value in source) { - if (i++ > 0) _ = sb.Append(delimiter); + if (i++ > 0) + _ = sb.Append(delimiter); + _ = append(sb, value); } diff --git a/Source/SuperLinq/Transpose.cs b/Source/SuperLinq/Transpose.cs index 8d7b42ade..fb040297f 100644 --- a/Source/SuperLinq/Transpose.cs +++ b/Source/SuperLinq/Transpose.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { @@ -37,10 +37,9 @@ static IEnumerable> Core(IEnumerable> source) { var column = new T[list.Count]; var count = 0; + for (; list.MoveNext(count); count++) - { column[count] = list.Current(count); - } if (count == 0) yield break; diff --git a/Source/SuperLinq/UnreachableException.cs b/Source/SuperLinq/UnreachableException.cs index 385d21945..0cc0b40af 100644 --- a/Source/SuperLinq/UnreachableException.cs +++ b/Source/SuperLinq/UnreachableException.cs @@ -21,8 +21,7 @@ public sealed class UnreachableException : Exception /// public UnreachableException() : base("The program executed an instruction that was thought to be unreachable.") - { - } + { } /// /// Initializes a new instance of the @@ -31,8 +30,7 @@ public UnreachableException() /// The error message that explains the reason for the exception. public UnreachableException(string? message) : base(message) - { - } + { } /// /// Initializes a new instance of the @@ -43,7 +41,6 @@ public UnreachableException(string? message) /// The exception that is the cause of the current exception. public UnreachableException(string? message, Exception? innerException) : base(message, innerException) - { - } + { } } #endif diff --git a/Source/SuperLinq/Using.cs b/Source/SuperLinq/Using.cs index 34cbe20b3..d7ccbcc3a 100644 --- a/Source/SuperLinq/Using.cs +++ b/Source/SuperLinq/Using.cs @@ -28,7 +28,7 @@ public static partial class SuperEnumerable /// /// and are evaluated lazily, once /// enumeration has begun. The value returned by will be disposed after the - /// enumeration has completed. + /// enumeration has completed. /// /// /// The values returned by and are not diff --git a/Source/SuperLinq/ValueTupleComparer.cs b/Source/SuperLinq/ValueTupleComparer.cs index fda6f72b7..a44f59bda 100644 --- a/Source/SuperLinq/ValueTupleComparer.cs +++ b/Source/SuperLinq/ValueTupleComparer.cs @@ -48,8 +48,9 @@ private sealed class Comparer( public int Compare([AllowNull] (T1, T2) x, [AllowNull] (T1, T2) y) { var result = _comparer1.Compare(x.Item1, y.Item1); - return result != 0 ? result : - _comparer2.Compare(x.Item2, y.Item2); + return result != 0 + ? result + : _comparer2.Compare(x.Item2, y.Item2); } } } diff --git a/Source/SuperLinq/ValueTupleEqualityComparer.cs b/Source/SuperLinq/ValueTupleEqualityComparer.cs index 683c31bfc..e8f11e3d4 100644 --- a/Source/SuperLinq/ValueTupleEqualityComparer.cs +++ b/Source/SuperLinq/ValueTupleEqualityComparer.cs @@ -33,9 +33,10 @@ private sealed class ItemEqualityComparer( { private readonly IEqualityComparer _comparer1 = comparer1 ?? EqualityComparer.Default; - public bool Equals(ValueTuple x, - ValueTuple y) - => _comparer1.Equals(x.Item1, y.Item1); + public bool Equals( + ValueTuple x, + ValueTuple y + ) => _comparer1.Equals(x.Item1, y.Item1); public int GetHashCode(ValueTuple obj) => obj.Item1 is null ? 0 : _comparer1.GetHashCode(obj.Item1); @@ -68,7 +69,8 @@ public int GetHashCode(ValueTuple obj) => IEqualityComparer? comparer2) => new ItemEqualityComparer( comparer1, - comparer2); + comparer2 + ); private sealed class ItemEqualityComparer( IEqualityComparer? comparer1, @@ -78,9 +80,10 @@ private sealed class ItemEqualityComparer( private readonly IEqualityComparer _comparer1 = comparer1 ?? EqualityComparer.Default; private readonly IEqualityComparer _comparer2 = comparer2 ?? EqualityComparer.Default; - public bool Equals((T1, T2) x, - (T1, T2) y) - => _comparer1.Equals(x.Item1, y.Item1) + public bool Equals( + (T1, T2) x, + (T1, T2) y + ) => _comparer1.Equals(x.Item1, y.Item1) && _comparer2.Equals(x.Item2, y.Item2); public int GetHashCode((T1, T2) obj) => diff --git a/Source/SuperLinq/WhereLag.cs b/Source/SuperLinq/WhereLag.cs index 2155e3c22..3c0ce257a 100644 --- a/Source/SuperLinq/WhereLag.cs +++ b/Source/SuperLinq/WhereLag.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { @@ -72,7 +72,12 @@ public static IEnumerable WhereLag(this IEnumerable s /// This operator evaluates in a deferred and streaming manner. /// /// - public static IEnumerable WhereLag(this IEnumerable source, int offset, TSource defaultLagValue, Func predicate) + public static IEnumerable WhereLag( + this IEnumerable source, + int offset, + TSource defaultLagValue, + Func predicate + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(predicate); diff --git a/Source/SuperLinq/WhereLead.cs b/Source/SuperLinq/WhereLead.cs index d068e392a..a9bf8432d 100644 --- a/Source/SuperLinq/WhereLead.cs +++ b/Source/SuperLinq/WhereLead.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { @@ -34,7 +34,11 @@ public static partial class SuperEnumerable /// This operator evaluates in a deferred and streaming manner. /// /// - public static IEnumerable WhereLead(this IEnumerable source, int offset, Func predicate) + public static IEnumerable WhereLead( + this IEnumerable source, + int offset, + Func predicate + ) { return source.WhereLead(offset, default!, predicate); } @@ -70,7 +74,12 @@ public static IEnumerable WhereLead(this IEnumerable /// This operator evaluates in a deferred and streaming manner. /// /// - public static IEnumerable WhereLead(this IEnumerable source, int offset, TSource defaultLeadValue, Func predicate) + public static IEnumerable WhereLead( + this IEnumerable source, + int offset, + TSource defaultLeadValue, + Func predicate + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(predicate); @@ -78,7 +87,12 @@ public static IEnumerable WhereLead(this IEnumerable return Core(source, offset, defaultLeadValue, predicate); - static IEnumerable Core(IEnumerable source, int offset, TSource defaultLeadValue, Func predicate) + static IEnumerable Core( + IEnumerable source, + int offset, + TSource defaultLeadValue, + Func predicate + ) { var queue = new Queue(offset + 1); diff --git a/Source/SuperLinq/Window.Buffered.Impl.cs b/Source/SuperLinq/Window.Buffered.Impl.cs index 77bfd9efb..dd9c0b026 100644 --- a/Source/SuperLinq/Window.Buffered.Impl.cs +++ b/Source/SuperLinq/Window.Buffered.Impl.cs @@ -1,8 +1,14 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { - private enum WindowType { Normal, Left, Right, } + private enum WindowType + { + Normal, + Left, + Right, + } + private static IEnumerable WindowImpl( IEnumerable source, TSource[] array, @@ -33,8 +39,6 @@ private static IEnumerable WindowImpl( yield break; for (var j = n == size ? 1 : 0; j < n; j++) - { yield return projector(new ArraySegment(array, j, n - j)); - } } } diff --git a/Source/SuperLinq/Window.cs b/Source/SuperLinq/Window.cs index 02d9d6c5b..3524e309a 100644 --- a/Source/SuperLinq/Window.cs +++ b/Source/SuperLinq/Window.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { @@ -50,6 +50,7 @@ static IEnumerable> Core(IEnumerable source, int size) { if (!e.MoveNext()) yield break; + window[i] = e.Current; } diff --git a/Source/SuperLinq/WindowLeft.Buffered.cs b/Source/SuperLinq/WindowLeft.Buffered.cs index 9bee7002f..f1e597015 100644 --- a/Source/SuperLinq/WindowLeft.Buffered.cs +++ b/Source/SuperLinq/WindowLeft.Buffered.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { @@ -115,12 +115,12 @@ public static IEnumerable WindowLeft( /// /// The sequence over which to create the sliding window. /// - /// - /// Size of the sliding window. - /// /// /// An array to use as a buffer for each subsequence. /// + /// + /// Size of the sliding window. + /// /// /// A transform function to apply to each window. /// diff --git a/Source/SuperLinq/WindowLeft.cs b/Source/SuperLinq/WindowLeft.cs index adc42ba17..1309fdba2 100644 --- a/Source/SuperLinq/WindowLeft.cs +++ b/Source/SuperLinq/WindowLeft.cs @@ -159,6 +159,7 @@ protected override IList ElementAt(int index) var max = (uint)source.Count; for (int i = 0, j = index; i < arr.Length && j < max; i++, j++) arr[i] = source[j]; + return arr; } } diff --git a/Source/SuperLinq/WindowRight.cs b/Source/SuperLinq/WindowRight.cs index bbd80aff0..79020c12d 100644 --- a/Source/SuperLinq/WindowRight.cs +++ b/Source/SuperLinq/WindowRight.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { @@ -90,11 +90,9 @@ int size protected override IEnumerable> GetEnumerable() { if (source.Count == 0) - { yield break; - } - var window = new T[1] { source[0], }; + var window = new T[1] { source[0] }; var max = (uint)Math.Min(source.Count, size); for (var i = 1; i < max; i++) { @@ -140,6 +138,7 @@ protected override IList ElementAt(int index) var max = (uint)index + 1; for (int i = 0, j = index - size + 1; i < arr.Length && j < max; i++, j++) arr[i] = source[j]; + return arr; } } diff --git a/Source/SuperLinq/ZipMap.cs b/Source/SuperLinq/ZipMap.cs index ef4d1cbed..5e1d6bbbb 100644 --- a/Source/SuperLinq/ZipMap.cs +++ b/Source/SuperLinq/ZipMap.cs @@ -1,4 +1,4 @@ -namespace SuperLinq; +namespace SuperLinq; public static partial class SuperEnumerable { @@ -30,7 +30,10 @@ public static partial class SuperEnumerable /// This operator uses deferred execution and streams its results. /// /// - public static IEnumerable<(TSource item, TResult result)> ZipMap(this IEnumerable source, Func selector) + public static IEnumerable<(TSource item, TResult result)> ZipMap( + this IEnumerable source, + Func selector + ) { ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(selector); diff --git a/Tests/SuperLinq.Async.Test/AggregateByTest.cs b/Tests/SuperLinq.Async.Test/AggregateByTest.cs index 39ae63e03..eddd8eb83 100644 --- a/Tests/SuperLinq.Async.Test/AggregateByTest.cs +++ b/Tests/SuperLinq.Async.Test/AggregateByTest.cs @@ -65,7 +65,7 @@ await ts.AggregateBy(keySelector, seedSelector, func, comparer) yield return WrapArgs( source: ["Bob", "bob", "tim", "Bob", "Tim"], keySelector: x => x, - seedSelector: x => string.Empty, + seedSelector: x => "", func: (x, y) => x + y, comparer: null, expected: new Dictionary(StringComparer.Ordinal) @@ -79,7 +79,7 @@ await ts.AggregateBy(keySelector, seedSelector, func, comparer) yield return WrapArgs( source: ["Bob", "bob", "tim", "Bob", "Tim"], keySelector: x => x, - seedSelector: x => string.Empty, + seedSelector: x => "", func: (x, y) => x + y, StringComparer.OrdinalIgnoreCase, expected: new Dictionary(StringComparer.Ordinal) diff --git a/Tests/SuperLinq.Async.Test/AmbTest.cs b/Tests/SuperLinq.Async.Test/AmbTest.cs index a0cba12dd..307177af8 100644 --- a/Tests/SuperLinq.Async.Test/AmbTest.cs +++ b/Tests/SuperLinq.Async.Test/AmbTest.cs @@ -34,7 +34,7 @@ public async Task AmbEmptyReturnsFirst(int sequenceNumber, bool asyncEmpty) var seq2 = sequenceNumber == 2 ? empty : async; var seq3 = sequenceNumber == 3 ? empty : async; - var ts = new[] { seq1, seq2, seq3, }; + var ts = new[] { seq1, seq2, seq3 }; var result = ts.Amb(); @@ -60,7 +60,7 @@ public async Task AmbSyncReturnsFirst(int sequenceNumber) var seq2 = sequenceNumber == 2 ? sync : async; var seq3 = sequenceNumber == 3 ? sync : async; - var ts = new[] { seq1, seq2, seq3, }; + var ts = new[] { seq1, seq2, seq3 }; var result = ts.Amb(); @@ -89,7 +89,7 @@ public async Task AmbAsyncShortestComesFirst(int sequenceNumber) await using var seq2 = (sequenceNumber == 2 ? shorter : longer).AsTestingSequence(); await using var seq3 = (sequenceNumber == 3 ? shorter : longer).AsTestingSequence(); - var ts = new[] { seq1, seq2, seq3, }; + var ts = new[] { seq1, seq2, seq3 }; var result = ts.Amb(); diff --git a/Tests/SuperLinq.Async.Test/CatchTest.cs b/Tests/SuperLinq.Async.Test/CatchTest.cs index 7f73579f6..049a8ab92 100644 --- a/Tests/SuperLinq.Async.Test/CatchTest.cs +++ b/Tests/SuperLinq.Async.Test/CatchTest.cs @@ -14,7 +14,7 @@ public void CatchIsLazy() [Fact] public async Task CatchThrowsDelayedExceptionOnNullSource() { - var seq = AsyncSuperEnumerable.Catch(new IAsyncEnumerable[] { null!, }); + var seq = AsyncSuperEnumerable.Catch(new IAsyncEnumerable[] { null! }); _ = await Assert.ThrowsAsync(async () => await seq.Consume()); } @@ -88,7 +88,7 @@ public async Task CatchMultipleSequencesWithNoExceptionOnSequence(int sequenceNu await using var ts4 = (cnt++ == sequenceNumber ? AsyncEnumerable.Range(1, 10) : AsyncSeqExceptionAt(5)).AsTestingSequence(); await using var ts5 = (cnt++ == sequenceNumber ? AsyncEnumerable.Range(1, 10) : AsyncSeqExceptionAt(5)).AsTestingSequence(); - await using var seq = new[] { ts1, ts2, ts3, ts4, ts5, }.AsTestingSequence(); + await using var seq = new[] { ts1, ts2, ts3, ts4, ts5 }.AsTestingSequence(); var result = seq.Catch(); diff --git a/Tests/SuperLinq.Async.Test/CountDownTest.cs b/Tests/SuperLinq.Async.Test/CountDownTest.cs index 45f0a7e3a..589662d26 100644 --- a/Tests/SuperLinq.Async.Test/CountDownTest.cs +++ b/Tests/SuperLinq.Async.Test/CountDownTest.cs @@ -36,7 +36,7 @@ private static IEnumerable GetData(Func selector) Count = count, Countdown = countdown, }) - select new object[] { e.Source, e.Count, e.Source.Zip(e.Countdown, ValueTuple.Create), }; + select new object[] { e.Source, e.Count, e.Source.Zip(e.Countdown, ValueTuple.Create) }; [Theory, MemberData(nameof(SequenceData))] public async Task WithSequence(int[] xs, int count, IEnumerable<(int, int?)> expected) diff --git a/Tests/SuperLinq.Async.Test/DensePartialSortByTest.cs b/Tests/SuperLinq.Async.Test/DensePartialSortByTest.cs index 7a5165dfe..308d55a43 100644 --- a/Tests/SuperLinq.Async.Test/DensePartialSortByTest.cs +++ b/Tests/SuperLinq.Async.Test/DensePartialSortByTest.cs @@ -21,7 +21,7 @@ public async Task DensePartialSortBy() .DensePartialSortBy(3, e => e.Key); await sorted.Select(e => e.Value).AssertSequenceEqual( - ns.Take(3).SelectMany(x => new[] { x, x, })); + ns.Take(3).SelectMany(x => new[] { x, x })); } [Theory] @@ -45,7 +45,7 @@ public async Task DensePartialSortWithOrder(OrderByDirection direction) ns = ns.Reverse(); await sorted.Select(e => e.Value).AssertSequenceEqual( - ns.Take(3).SelectMany(x => new[] { x, x, })); + ns.Take(3).SelectMany(x => new[] { x, x })); } [Fact] diff --git a/Tests/SuperLinq.Async.Test/DuplicatesTest.cs b/Tests/SuperLinq.Async.Test/DuplicatesTest.cs index 39f0b6197..915b1c199 100644 --- a/Tests/SuperLinq.Async.Test/DuplicatesTest.cs +++ b/Tests/SuperLinq.Async.Test/DuplicatesTest.cs @@ -9,9 +9,9 @@ public void DuplicatesIsLazy() } [Theory] - [InlineData(new int[] { 1, 2, 3, }, new int[] { })] - [InlineData(new int[] { 1, 2, 1, 3, 1, 2, 1, }, new int[] { 1, 2, })] - [InlineData(new int[] { 3, 3, 2, 2, 1, 1, }, new int[] { 3, 2, 1, })] + [InlineData(new int[] { 1, 2, 3 }, new int[] { })] + [InlineData(new int[] { 1, 2, 1, 3, 1, 2, 1 }, new int[] { 1, 2 })] + [InlineData(new int[] { 3, 3, 2, 2, 1, 1 }, new int[] { 3, 2, 1 })] public async Task DuplicatesBehavior(IEnumerable source, IEnumerable expected) { await using var ts = source.AsTestingSequence(); @@ -38,13 +38,13 @@ public static IEnumerable GetStringParameters() { new string[] { "foo", "FOO", "bar", "qux" }, StringComparer.OrdinalIgnoreCase, - new string[] { "FOO", }, + new string[] { "FOO" }, }; yield return new object[] { new string[] { "Bar", "foo", "FOO", "bar", "qux" }, StringComparer.OrdinalIgnoreCase, - new string[] { "FOO", "bar", }, + new string[] { "FOO", "bar" }, }; } diff --git a/Tests/SuperLinq.Async.Test/ElementAtTest.cs b/Tests/SuperLinq.Async.Test/ElementAtTest.cs index f53c67529..972487cdc 100644 --- a/Tests/SuperLinq.Async.Test/ElementAtTest.cs +++ b/Tests/SuperLinq.Async.Test/ElementAtTest.cs @@ -46,16 +46,16 @@ public async Task FromEndIndexOutOfRangeInt() [Fact] public async Task FromStartIndexString() { - var q = AsyncSeq("!@#$%^", "C", "AAA", "", "Calling Twice", "SoS", string.Empty); + var q = AsyncSeq("!@#$%^", "C", "AAA", "", "Calling Twice", "SoS", ""); - Assert.Equal(string.Empty, await q.ElementAtAsync(new Index(3))); - Assert.Equal(string.Empty, await q.ElementAtOrDefaultAsync(new Index(3))); + Assert.Equal("", await q.ElementAtAsync(new Index(3))); + Assert.Equal("", await q.ElementAtOrDefaultAsync(new Index(3))); } [Fact] public async Task FromStartIndexOutOfRangeString() { - var q = AsyncSeq("!@#$%^", "C", "AAA", "", "Calling Twice", "SoS", string.Empty); + var q = AsyncSeq("!@#$%^", "C", "AAA", "", "Calling Twice", "SoS", ""); _ = await Assert.ThrowsAsync(async () => await q.ElementAtAsync(new Index(10))); @@ -65,16 +65,16 @@ public async Task FromStartIndexOutOfRangeString() [Fact] public async Task FromEndIndexString() { - var q = AsyncSeq("!@#$%^", "C", "AAA", "", "Calling Twice", "SoS", string.Empty); + var q = AsyncSeq("!@#$%^", "C", "AAA", "", "Calling Twice", "SoS", ""); - Assert.Equal(string.Empty, await q.ElementAtAsync(^4)); - Assert.Equal(string.Empty, await q.ElementAtOrDefaultAsync(^4)); + Assert.Equal("", await q.ElementAtAsync(^4)); + Assert.Equal("", await q.ElementAtOrDefaultAsync(^4)); } [Fact] public async Task FromEndIndexOutOfRangeString() { - var q = AsyncSeq("!@#$%^", "C", "AAA", "", "Calling Twice", "SoS", string.Empty); + var q = AsyncSeq("!@#$%^", "C", "AAA", "", "Calling Twice", "SoS", ""); _ = await Assert.ThrowsAsync(async () => await q.ElementAtAsync(^10)); diff --git a/Tests/SuperLinq.Async.Test/FoldTest.cs b/Tests/SuperLinq.Async.Test/FoldTest.cs index 40038930e..81454ffc7 100644 --- a/Tests/SuperLinq.Async.Test/FoldTest.cs +++ b/Tests/SuperLinq.Async.Test/FoldTest.cs @@ -28,21 +28,21 @@ public async Task Fold() { const string Alphabet = "abcdefghijklmnopqrstuvwxyz"; - await using (var ts = Alphabet.Take(1).AsTestingSequence()) Assert.Equal("a", await ts.Fold(a => string.Join(string.Empty, a))); - await using (var ts = Alphabet.Take(2).AsTestingSequence()) Assert.Equal("ab", await ts.Fold((a, b) => string.Join(string.Empty, a, b))); - await using (var ts = Alphabet.Take(3).AsTestingSequence()) Assert.Equal("abc", await ts.Fold((a, b, c) => string.Join(string.Empty, a, b, c))); - await using (var ts = Alphabet.Take(4).AsTestingSequence()) Assert.Equal("abcd", await ts.Fold((a, b, c, d) => string.Join(string.Empty, a, b, c, d))); - await using (var ts = Alphabet.Take(5).AsTestingSequence()) Assert.Equal("abcde", await ts.Fold((a, b, c, d, e) => string.Join(string.Empty, a, b, c, d, e))); - await using (var ts = Alphabet.Take(6).AsTestingSequence()) Assert.Equal("abcdef", await ts.Fold((a, b, c, d, e, f) => string.Join(string.Empty, a, b, c, d, e, f))); - await using (var ts = Alphabet.Take(7).AsTestingSequence()) Assert.Equal("abcdefg", await ts.Fold((a, b, c, d, e, f, g) => string.Join(string.Empty, a, b, c, d, e, f, g))); - await using (var ts = Alphabet.Take(8).AsTestingSequence()) Assert.Equal("abcdefgh", await ts.Fold((a, b, c, d, e, f, g, h) => string.Join(string.Empty, a, b, c, d, e, f, g, h))); - await using (var ts = Alphabet.Take(9).AsTestingSequence()) Assert.Equal("abcdefghi", await ts.Fold((a, b, c, d, e, f, g, h, i) => string.Join(string.Empty, a, b, c, d, e, f, g, h, i))); - await using (var ts = Alphabet.Take(10).AsTestingSequence()) Assert.Equal("abcdefghij", await ts.Fold((a, b, c, d, e, f, g, h, i, j) => string.Join(string.Empty, a, b, c, d, e, f, g, h, i, j))); - await using (var ts = Alphabet.Take(11).AsTestingSequence()) Assert.Equal("abcdefghijk", await ts.Fold((a, b, c, d, e, f, g, h, i, j, k) => string.Join(string.Empty, a, b, c, d, e, f, g, h, i, j, k))); - await using (var ts = Alphabet.Take(12).AsTestingSequence()) Assert.Equal("abcdefghijkl", await ts.Fold((a, b, c, d, e, f, g, h, i, j, k, l) => string.Join(string.Empty, a, b, c, d, e, f, g, h, i, j, k, l))); - await using (var ts = Alphabet.Take(13).AsTestingSequence()) Assert.Equal("abcdefghijklm", await ts.Fold((a, b, c, d, e, f, g, h, i, j, k, l, m) => string.Join(string.Empty, a, b, c, d, e, f, g, h, i, j, k, l, m))); - await using (var ts = Alphabet.Take(14).AsTestingSequence()) Assert.Equal("abcdefghijklmn", await ts.Fold((a, b, c, d, e, f, g, h, i, j, k, l, m, n) => string.Join(string.Empty, a, b, c, d, e, f, g, h, i, j, k, l, m, n))); - await using (var ts = Alphabet.Take(15).AsTestingSequence()) Assert.Equal("abcdefghijklmno", await ts.Fold((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) => string.Join(string.Empty, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))); - await using (var ts = Alphabet.Take(16).AsTestingSequence()) Assert.Equal("abcdefghijklmnop", await ts.Fold((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) => string.Join(string.Empty, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p))); + await using (var ts = Alphabet.Take(1).AsTestingSequence()) Assert.Equal("a", await ts.Fold(a => string.Join("", a))); + await using (var ts = Alphabet.Take(2).AsTestingSequence()) Assert.Equal("ab", await ts.Fold((a, b) => string.Join("", a, b))); + await using (var ts = Alphabet.Take(3).AsTestingSequence()) Assert.Equal("abc", await ts.Fold((a, b, c) => string.Join("", a, b, c))); + await using (var ts = Alphabet.Take(4).AsTestingSequence()) Assert.Equal("abcd", await ts.Fold((a, b, c, d) => string.Join("", a, b, c, d))); + await using (var ts = Alphabet.Take(5).AsTestingSequence()) Assert.Equal("abcde", await ts.Fold((a, b, c, d, e) => string.Join("", a, b, c, d, e))); + await using (var ts = Alphabet.Take(6).AsTestingSequence()) Assert.Equal("abcdef", await ts.Fold((a, b, c, d, e, f) => string.Join("", a, b, c, d, e, f))); + await using (var ts = Alphabet.Take(7).AsTestingSequence()) Assert.Equal("abcdefg", await ts.Fold((a, b, c, d, e, f, g) => string.Join("", a, b, c, d, e, f, g))); + await using (var ts = Alphabet.Take(8).AsTestingSequence()) Assert.Equal("abcdefgh", await ts.Fold((a, b, c, d, e, f, g, h) => string.Join("", a, b, c, d, e, f, g, h))); + await using (var ts = Alphabet.Take(9).AsTestingSequence()) Assert.Equal("abcdefghi", await ts.Fold((a, b, c, d, e, f, g, h, i) => string.Join("", a, b, c, d, e, f, g, h, i))); + await using (var ts = Alphabet.Take(10).AsTestingSequence()) Assert.Equal("abcdefghij", await ts.Fold((a, b, c, d, e, f, g, h, i, j) => string.Join("", a, b, c, d, e, f, g, h, i, j))); + await using (var ts = Alphabet.Take(11).AsTestingSequence()) Assert.Equal("abcdefghijk", await ts.Fold((a, b, c, d, e, f, g, h, i, j, k) => string.Join("", a, b, c, d, e, f, g, h, i, j, k))); + await using (var ts = Alphabet.Take(12).AsTestingSequence()) Assert.Equal("abcdefghijkl", await ts.Fold((a, b, c, d, e, f, g, h, i, j, k, l) => string.Join("", a, b, c, d, e, f, g, h, i, j, k, l))); + await using (var ts = Alphabet.Take(13).AsTestingSequence()) Assert.Equal("abcdefghijklm", await ts.Fold((a, b, c, d, e, f, g, h, i, j, k, l, m) => string.Join("", a, b, c, d, e, f, g, h, i, j, k, l, m))); + await using (var ts = Alphabet.Take(14).AsTestingSequence()) Assert.Equal("abcdefghijklmn", await ts.Fold((a, b, c, d, e, f, g, h, i, j, k, l, m, n) => string.Join("", a, b, c, d, e, f, g, h, i, j, k, l, m, n))); + await using (var ts = Alphabet.Take(15).AsTestingSequence()) Assert.Equal("abcdefghijklmno", await ts.Fold((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) => string.Join("", a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))); + await using (var ts = Alphabet.Take(16).AsTestingSequence()) Assert.Equal("abcdefghijklmnop", await ts.Fold((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) => string.Join("", a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p))); } } diff --git a/Tests/SuperLinq.Async.Test/FullOuterJoinTest.cs b/Tests/SuperLinq.Async.Test/FullOuterJoinTest.cs index 1b7105d39..f4b9bb144 100644 --- a/Tests/SuperLinq.Async.Test/FullOuterJoinTest.cs +++ b/Tests/SuperLinq.Async.Test/FullOuterJoinTest.cs @@ -2,7 +2,7 @@ namespace Test.Async; -public enum JoinOperation { None, Loop, Hash, Merge, } +public enum JoinOperation { None, Loop, Hash, Merge } public sealed class FullOuterJoinTest { @@ -22,7 +22,7 @@ public sealed class FullOuterJoinTest }; public static IEnumerable GetFullOuterJoins() => - new[] { Hash, Merge, }.Cartesian(new[] { false, true, }, (x, y) => new object[] { x, y, }); + new[] { Hash, Merge }.Cartesian(new[] { false, true }, (x, y) => new object[] { x, y }); [Theory, MemberData(nameof(GetFullOuterJoins))] public void FullOuterJoinIsLazy(JoinOperation op, bool passProjectors) diff --git a/Tests/SuperLinq.Async.Test/HasDuplicatesTest.cs b/Tests/SuperLinq.Async.Test/HasDuplicatesTest.cs index a0ba51878..cc7b6aa49 100644 --- a/Tests/SuperLinq.Async.Test/HasDuplicatesTest.cs +++ b/Tests/SuperLinq.Async.Test/HasDuplicatesTest.cs @@ -12,9 +12,9 @@ public async Task DuplicatesDoesNotEnumerateUnnecessarily() } [Theory] - [InlineData(new int[] { 1, 2, 3, }, false)] - [InlineData(new int[] { 1, 2, 1, 3, 1, 2, 1, }, true)] - [InlineData(new int[] { 3, 3, 2, 2, 1, 1, }, true)] + [InlineData(new int[] { 1, 2, 3 }, false)] + [InlineData(new int[] { 1, 2, 1, 3, 1, 2, 1 }, true)] + [InlineData(new int[] { 3, 3, 2, 2, 1, 1 }, true)] public async Task DuplicatesBehavior(IEnumerable source, bool expected) { await using var ts = source.AsTestingSequence(); diff --git a/Tests/SuperLinq.Async.Test/InnerJoinTest.cs b/Tests/SuperLinq.Async.Test/InnerJoinTest.cs index f91ea66b7..04dba07b3 100644 --- a/Tests/SuperLinq.Async.Test/InnerJoinTest.cs +++ b/Tests/SuperLinq.Async.Test/InnerJoinTest.cs @@ -22,7 +22,7 @@ public sealed class InnerJoinTest }; public static IEnumerable GetInnerJoins() => - new[] { Loop, Hash, Merge, }.Cartesian(new[] { false, true, }, (x, y) => new object[] { x, y, }); + new[] { Loop, Hash, Merge }.Cartesian(new[] { false, true }, (x, y) => new object[] { x, y }); [Theory, MemberData(nameof(GetInnerJoins))] public void InnerJoinIsLazy(JoinOperation op, bool passProjectors) diff --git a/Tests/SuperLinq.Async.Test/InterleaveTest.cs b/Tests/SuperLinq.Async.Test/InterleaveTest.cs index 0a7c7e1d9..89c3e76b7 100644 --- a/Tests/SuperLinq.Async.Test/InterleaveTest.cs +++ b/Tests/SuperLinq.Async.Test/InterleaveTest.cs @@ -124,7 +124,7 @@ public async Task TestInterleaveManyImbalanceStrategySkip() await using var sequenceE = TestingSequence.Of(4, 7, 10, 13, 15, 17); var iterations = 0; - var sequences = new[] { sequenceA, sequenceB, sequenceC, sequenceD, sequenceE, } + var sequences = new[] { sequenceA, sequenceB, sequenceC, sequenceD, sequenceE } .Do>(_ => iterations++); var result = sequences.Interleave(); diff --git a/Tests/SuperLinq.Async.Test/LagTest.cs b/Tests/SuperLinq.Async.Test/LagTest.cs index 867bec355..8d13b0f7d 100644 --- a/Tests/SuperLinq.Async.Test/LagTest.cs +++ b/Tests/SuperLinq.Async.Test/LagTest.cs @@ -131,7 +131,7 @@ await result.AssertSequenceEqual( public async Task TestLagWithNonNullableReferences() { await using var words = TestingSequence.Of("foo", "bar", "baz", "qux"); - var empty = string.Empty; + var empty = ""; var result = words.Lag(2, empty, (a, b) => new { A = a, B = b }); await result.AssertSequenceEqual( new { A = "foo", B = empty }, diff --git a/Tests/SuperLinq.Async.Test/LeadTest.cs b/Tests/SuperLinq.Async.Test/LeadTest.cs index 030140ccc..eb91faf44 100644 --- a/Tests/SuperLinq.Async.Test/LeadTest.cs +++ b/Tests/SuperLinq.Async.Test/LeadTest.cs @@ -139,11 +139,11 @@ public async Task TestLagWithNonNullableReferences() { await using var words = TestingSequence.Of("foo", "bar", "baz", "qux"); - var result = words.Lead(2, string.Empty, (a, b) => new { A = a, B = b }); + var result = words.Lead(2, "", (a, b) => new { A = a, B = b }); await result.AssertSequenceEqual( new { A = "foo", B = "baz" }, new { A = "bar", B = "qux" }, - new { A = "baz", B = string.Empty }, - new { A = "qux", B = string.Empty }); + new { A = "baz", B = "" }, + new { A = "qux", B = "" }); } } diff --git a/Tests/SuperLinq.Async.Test/LeftOuterJoin.cs b/Tests/SuperLinq.Async.Test/LeftOuterJoin.cs index d0056fda0..085c166f9 100644 --- a/Tests/SuperLinq.Async.Test/LeftOuterJoin.cs +++ b/Tests/SuperLinq.Async.Test/LeftOuterJoin.cs @@ -22,7 +22,7 @@ public sealed class LeftOuterJoinTest }; public static IEnumerable GetLeftOuterJoins() => - new[] { Loop, Hash, Merge, }.Cartesian(new[] { false, true, }, (x, y) => new object[] { x, y, }); + new[] { Loop, Hash, Merge }.Cartesian(new[] { false, true }, (x, y) => new object[] { x, y }); [Theory, MemberData(nameof(GetLeftOuterJoins))] public void LeftOuterJoinIsLazy(JoinOperation op, bool passProjectors) diff --git a/Tests/SuperLinq.Async.Test/MemoizeTest.cs b/Tests/SuperLinq.Async.Test/MemoizeTest.cs index 04639f871..0568e4c94 100644 --- a/Tests/SuperLinq.Async.Test/MemoizeTest.cs +++ b/Tests/SuperLinq.Async.Test/MemoizeTest.cs @@ -270,6 +270,7 @@ public async Task MemoizeRethrowsErrorDuringIterationStartToAllsUntilReset() await using (var r1 = buffer.Read()) await using (var r2 = buffer.Read()) Guard.IsTrue(await r1.Read() == await r2.Read()); + Assert.Equal(1, buffer.Count); } diff --git a/Tests/SuperLinq.Async.Test/OnErrorResumeNextTest.cs b/Tests/SuperLinq.Async.Test/OnErrorResumeNextTest.cs index 1296ee2ad..9ffac42e0 100644 --- a/Tests/SuperLinq.Async.Test/OnErrorResumeNextTest.cs +++ b/Tests/SuperLinq.Async.Test/OnErrorResumeNextTest.cs @@ -44,7 +44,7 @@ public async Task OnErrorResumeNextMultipleSequencesWithNoExceptionOnSequence(in await using var ts4 = (cnt++ == sequenceNumber ? AsyncEnumerable.Range(1, 10) : AsyncSeqExceptionAt(5)).AsTestingSequence(); await using var ts5 = (cnt++ == sequenceNumber ? AsyncEnumerable.Range(1, 10) : AsyncSeqExceptionAt(5)).AsTestingSequence(); - await using var seq = new[] { ts1, ts2, ts3, ts4, ts5, }.AsTestingSequence(); + await using var seq = new[] { ts1, ts2, ts3, ts4, ts5 }.AsTestingSequence(); var result = seq.OnErrorResumeNext(); diff --git a/Tests/SuperLinq.Async.Test/OrderByTest.cs b/Tests/SuperLinq.Async.Test/OrderByTest.cs index 333efcc4f..bb2d62d68 100644 --- a/Tests/SuperLinq.Async.Test/OrderByTest.cs +++ b/Tests/SuperLinq.Async.Test/OrderByTest.cs @@ -64,12 +64,12 @@ public async Task TestOrderByComparerPreserved() public async Task TestThenBySelectorPreserved() { var sequence = AsyncSeq( - new { A = 2, B = 0, }, - new { A = 1, B = 5, }, - new { A = 2, B = 2, }, - new { A = 1, B = 3, }, - new { A = 1, B = 4, }, - new { A = 2, B = 1, }); + new { A = 2, B = 0 }, + new { A = 1, B = 5 }, + new { A = 2, B = 2 }, + new { A = 1, B = 3 }, + new { A = 1, B = 4 }, + new { A = 2, B = 1 }); var resultA1 = sequence .OrderBy(x => x.A, OrderByDirection.Ascending) @@ -97,12 +97,12 @@ public async Task TestThenBySelectorPreserved() public async Task TestThenByComparerPreserved() { var sequence = AsyncSeq( - new { A = "2", B = "0", }, - new { A = "1", B = "5", }, - new { A = "2", B = "2", }, - new { A = "1", B = "3", }, - new { A = "1", B = "4", }, - new { A = "2", B = "1", }); + new { A = "2", B = "0" }, + new { A = "1", B = "5" }, + new { A = "2", B = "2" }, + new { A = "1", B = "3" }, + new { A = "1", B = "4" }, + new { A = "2", B = "1" }); var comparer = Comparer.Create( (a, b) => int.Parse(a, CultureInfo.InvariantCulture) diff --git a/Tests/SuperLinq.Async.Test/PadStartTest.cs b/Tests/SuperLinq.Async.Test/PadStartTest.cs index 70071e566..cdd7f4777 100644 --- a/Tests/SuperLinq.Async.Test/PadStartTest.cs +++ b/Tests/SuperLinq.Async.Test/PadStartTest.cs @@ -85,7 +85,7 @@ public async Task ReferenceTypeElements(ICollection source, int width, I { await using var xs = source.AsTestingSequence(); await xs - .PadStart(width, string.Empty) + .PadStart(width, "") .AssertSequenceEqual(expected); } } diff --git a/Tests/SuperLinq.Async.Test/PadTest.cs b/Tests/SuperLinq.Async.Test/PadTest.cs index dcf5c023d..aaa1dd403 100644 --- a/Tests/SuperLinq.Async.Test/PadTest.cs +++ b/Tests/SuperLinq.Async.Test/PadTest.cs @@ -93,8 +93,8 @@ public async Task PadNarrowSourceSequenceWithDefaultPadding() public async Task PadNarrowSourceSequenceWithNonDefaultPadding() { await using var sequence = TestingSequence.Of("foo", "bar", "baz"); - var result = sequence.Pad(5, string.Empty); - await result.AssertSequenceEqual("foo", "bar", "baz", string.Empty, string.Empty); + var result = sequence.Pad(5, ""); + await result.AssertSequenceEqual("foo", "bar", "baz", "", ""); } } } diff --git a/Tests/SuperLinq.Async.Test/ReplaceTest.cs b/Tests/SuperLinq.Async.Test/ReplaceTest.cs index 56b1833cd..0fce4a53e 100644 --- a/Tests/SuperLinq.Async.Test/ReplaceTest.cs +++ b/Tests/SuperLinq.Async.Test/ReplaceTest.cs @@ -23,7 +23,7 @@ public async Task ReplaceEmptySequence() } public static IEnumerable Indices() => - Enumerable.Range(0, 10).Select(i => new object[] { i, }); + Enumerable.Range(0, 10).Select(i => new object[] { i }); [Theory, MemberData(nameof(Indices))] public async Task ReplaceIntIndex(int index) diff --git a/Tests/SuperLinq.Async.Test/RightOuterJoin.cs b/Tests/SuperLinq.Async.Test/RightOuterJoin.cs index ae2ccef4e..df5574415 100644 --- a/Tests/SuperLinq.Async.Test/RightOuterJoin.cs +++ b/Tests/SuperLinq.Async.Test/RightOuterJoin.cs @@ -20,7 +20,7 @@ public sealed class RightOuterJoinTest }; public static IEnumerable GetRightOuterJoins() => - new[] { Hash, Merge, }.Cartesian(new[] { false, true, }, (x, y) => new object[] { x, y, }); + new[] { Hash, Merge }.Cartesian(new[] { false, true }, (x, y) => new object[] { x, y }); [Theory, MemberData(nameof(GetRightOuterJoins))] public void RightOuterJoinIsLazy(JoinOperation op, bool passProjectors) diff --git a/Tests/SuperLinq.Async.Test/ScanRightTest.cs b/Tests/SuperLinq.Async.Test/ScanRightTest.cs index 113162907..7d0c6d451 100644 --- a/Tests/SuperLinq.Async.Test/ScanRightTest.cs +++ b/Tests/SuperLinq.Async.Test/ScanRightTest.cs @@ -81,6 +81,6 @@ await result.AssertSequenceEqual( [Fact] public void ScanRightSeedIsLazy() { - _ = new AsyncBreakingSequence().ScanRight(string.Empty, BreakingFunc.Of()); + _ = new AsyncBreakingSequence().ScanRight("", BreakingFunc.Of()); } } diff --git a/Tests/SuperLinq.Async.Test/SegmentTest.cs b/Tests/SuperLinq.Async.Test/SegmentTest.cs index 3840f430c..f003bb9c6 100644 --- a/Tests/SuperLinq.Async.Test/SegmentTest.cs +++ b/Tests/SuperLinq.Async.Test/SegmentTest.cs @@ -65,8 +65,10 @@ public async Task TestFirstSegmentNeverEmpty() { await using (var sequence = Enumerable.Repeat(-1, 10).AsTestingSequence()) Assert.NotEmpty(await sequence.Segment(x => true).FirstAsync()); + await using (var sequence = Enumerable.Repeat(-1, 10).AsTestingSequence()) Assert.NotEmpty(await sequence.Segment((x, index) => true).FirstAsync()); + await using (var sequence = Enumerable.Repeat(-1, 10).AsTestingSequence()) Assert.NotEmpty(await sequence.Segment((x, prevX, index) => true).FirstAsync()); } @@ -79,8 +81,10 @@ public async Task TestSegmentationStartsWithSecondItem() { await using (var sequence = TestingSequence.Of(0)) Assert.NotEmpty(await sequence.Segment(BreakingFunc.Of()).FirstAsync()); + await using (var sequence = TestingSequence.Of(0)) Assert.NotEmpty(await sequence.Segment(BreakingFunc.Of()).FirstAsync()); + await using (var sequence = TestingSequence.Of(0)) Assert.NotEmpty(await sequence.Segment(BreakingFunc.Of()).FirstAsync()); } @@ -133,7 +137,7 @@ from e in new[] // input sequence do not start with a segment start new { Source = AsyncSeq(1, 2, 3, 4, 5), Expected = AsyncSeq(Seq(1, 2), Seq(3, 4, 5)) }, } - select new object[] { e.Source, e.Expected, }; + select new object[] { e.Source, e.Expected }; [Theory] [MemberData(nameof(TestData))] diff --git a/Tests/SuperLinq.Async.Test/SplitTest.cs b/Tests/SuperLinq.Async.Test/SplitTest.cs index 155abc2ba..abacf8fdb 100644 --- a/Tests/SuperLinq.Async.Test/SplitTest.cs +++ b/Tests/SuperLinq.Async.Test/SplitTest.cs @@ -14,7 +14,7 @@ public async Task SplitWithComparer() { await using var sequence = Enumerable.Range(1, 10).AsTestingSequence(); var result = sequence.Split(2, EqualityComparer.Create((x, y) => x % 2 == y % 2)); - await result.AssertSequenceEqual(Enumerable.Range(1, 5).Select(x => new[] { (x * 2) - 1, })); + await result.AssertSequenceEqual(Enumerable.Range(1, 5).Select(x => new[] { (x * 2) - 1 })); } [Fact] diff --git a/Tests/SuperLinq.Async.Test/TakeTest.cs b/Tests/SuperLinq.Async.Test/TakeTest.cs index 4f8cd753f..53b10dcd2 100644 --- a/Tests/SuperLinq.Async.Test/TakeTest.cs +++ b/Tests/SuperLinq.Async.Test/TakeTest.cs @@ -23,7 +23,7 @@ where x > int.MinValue [Fact] public async Task SameResultsRepeatCallsStringQuery() { - var q = (from x in new[] { "!@#$%^", "C", "AAA", "", "Calling Twice", "SoS", string.Empty } + var q = (from x in new[] { "!@#$%^", "C", "AAA", "", "Calling Twice", "SoS", "" } where !string.IsNullOrEmpty(x) select x).ToAsyncEnumerable(); diff --git a/Tests/SuperLinq.Async.Test/TestingSequence.cs b/Tests/SuperLinq.Async.Test/TestingSequence.cs index 416ff6803..847ee3095 100644 --- a/Tests/SuperLinq.Async.Test/TestingSequence.cs +++ b/Tests/SuperLinq.Async.Test/TestingSequence.cs @@ -90,6 +90,7 @@ ValueTask IAsyncDisposable.DisposeAsync() { if (_enumerationCount > 0) AssertTestingSequence(_disposedCount == _enumerationCount, ExpectedDisposal); + return default; } @@ -187,8 +188,10 @@ static async IAsyncEnumerable InvalidUsage(IAsyncEnumerable enumerable { await using (enumerable.GetAsyncEnumerator()) yield return 1; + await using (enumerable.GetAsyncEnumerator()) yield return 2; + await using (enumerable.GetAsyncEnumerator()) yield return 3; @@ -257,6 +260,7 @@ static async IAsyncEnumerable InvalidUsage(IAsyncEnumerable enumerable await using var enumerator = enumerable.GetAsyncEnumerator(); while (await enumerator.MoveNextAsync()) yield return enumerator.Current; + _ = await enumerator.MoveNextAsync(); await Task.Yield(); @@ -302,6 +306,7 @@ static async IAsyncEnumerable InvalidUsage(IAsyncEnumerable enumerable await using var enumerator = enumerable.GetAsyncEnumerator(); while (await enumerator.MoveNextAsync()) yield return enumerator.Current; + yield return enumerator.Current; await Task.Yield(); diff --git a/Tests/SuperLinq.Async.Test/WhereLagTest.cs b/Tests/SuperLinq.Async.Test/WhereLagTest.cs index 5369a1faf..3978bf03b 100644 --- a/Tests/SuperLinq.Async.Test/WhereLagTest.cs +++ b/Tests/SuperLinq.Async.Test/WhereLagTest.cs @@ -56,7 +56,7 @@ public async Task WhereLagWithNullableReferences() public async Task WhereLagWithNonNullableReferences() { await using var seq = Seq("foo", "bar", "baz", "qux").AsTestingSequence(); - var result = seq.WhereLag(2, string.Empty, (a, b) => b == "foo" || a == "foo"); + var result = seq.WhereLag(2, "", (a, b) => b == "foo" || a == "foo"); await result.AssertSequenceEqual("foo", "baz"); } } diff --git a/Tests/SuperLinq.Async.Test/WhereLeadTest.cs b/Tests/SuperLinq.Async.Test/WhereLeadTest.cs index 90146906c..470708156 100644 --- a/Tests/SuperLinq.Async.Test/WhereLeadTest.cs +++ b/Tests/SuperLinq.Async.Test/WhereLeadTest.cs @@ -56,7 +56,7 @@ public async Task WhereLeadWithNullableReferences() public async Task WhereLeadWithNonNullableReferences() { await using var seq = Seq("foo", "bar", "baz", "qux").AsTestingSequence(); - var result = seq.WhereLead(2, string.Empty, (a, b) => b == "baz" || a == "baz"); + var result = seq.WhereLead(2, "", (a, b) => b == "baz" || a == "baz"); await result.AssertSequenceEqual("foo", "baz"); } } diff --git a/Tests/SuperLinq.Test/AggregateByTest.cs b/Tests/SuperLinq.Test/AggregateByTest.cs index ea06d903a..a276fe698 100644 --- a/Tests/SuperLinq.Test/AggregateByTest.cs +++ b/Tests/SuperLinq.Test/AggregateByTest.cs @@ -67,7 +67,7 @@ public static void AggregateBy_HasExpectedOutput( yield return WrapArgs( source: ["Bob", "bob", "tim", "Bob", "Tim"], keySelector: x => x, - seedSelector: x => string.Empty, + seedSelector: x => "", func: (x, y) => x + y, comparer: null, expected: new Dictionary(StringComparer.Ordinal) @@ -81,7 +81,7 @@ public static void AggregateBy_HasExpectedOutput( yield return WrapArgs( source: ["Bob", "bob", "tim", "Bob", "Tim"], keySelector: x => x, - seedSelector: x => string.Empty, + seedSelector: x => "", func: (x, y) => x + y, StringComparer.OrdinalIgnoreCase, expected: new Dictionary(StringComparer.Ordinal) diff --git a/Tests/SuperLinq.Test/AggregateTest.cs b/Tests/SuperLinq.Test/AggregateTest.cs index 2dd1fb454..7450a0e32 100644 --- a/Tests/SuperLinq.Test/AggregateTest.cs +++ b/Tests/SuperLinq.Test/AggregateTest.cs @@ -69,7 +69,7 @@ from pair in pairs .ToArray(), } into t - select new object[] { t.Method, t.Args, t.Expectation, }; + select new object[] { t.Method, t.Args, t.Expectation }; [Theory, MemberData(nameof(AccumulatorsTestSource))] public void Accumulators(MethodInfo method, object[] args, object expected) diff --git a/Tests/SuperLinq.Test/AtLeastTest.cs b/Tests/SuperLinq.Test/AtLeastTest.cs index a13f5ab0a..bc19e54ab 100644 --- a/Tests/SuperLinq.Test/AtLeastTest.cs +++ b/Tests/SuperLinq.Test/AtLeastTest.cs @@ -31,7 +31,7 @@ public void AtLeastWithEmptySequenceHasAtLeastOneElement(IDisposableEnumerable seq) { using (seq) @@ -39,7 +39,7 @@ public void AtLeastWithSingleElementHasAtLeastZeroElements(IDisposableEnumerable } [Theory] - [MemberData(nameof(GetSequences), new int[] { 1, })] + [MemberData(nameof(GetSequences), new int[] { 1 })] public void AtLeastWithSingleElementHasAtLeastOneElement(IDisposableEnumerable seq) { using (seq) @@ -47,7 +47,7 @@ public void AtLeastWithSingleElementHasAtLeastOneElement(IDisposableEnumerable seq) { using (seq) @@ -55,7 +55,7 @@ public void AtLeastWithSingleElementHasAtLeastManyElements(IDisposableEnumerable } [Theory] - [MemberData(nameof(GetSequences), new int[] { 1, 2, 3, })] + [MemberData(nameof(GetSequences), new int[] { 1, 2, 3 })] public void AtLeastWithManyElementsHasAtLeastZeroElements(IDisposableEnumerable seq) { using (seq) @@ -63,7 +63,7 @@ public void AtLeastWithManyElementsHasAtLeastZeroElements(IDisposableEnumerable< } [Theory] - [MemberData(nameof(GetSequences), new int[] { 1, 2, 3, })] + [MemberData(nameof(GetSequences), new int[] { 1, 2, 3 })] public void AtLeastWithManyElementsHasAtLeastOneElement(IDisposableEnumerable seq) { using (seq) @@ -71,7 +71,7 @@ public void AtLeastWithManyElementsHasAtLeastOneElement(IDisposableEnumerable seq) { using (seq) diff --git a/Tests/SuperLinq.Test/AtMostTest.cs b/Tests/SuperLinq.Test/AtMostTest.cs index 82965df34..16ffb3135 100644 --- a/Tests/SuperLinq.Test/AtMostTest.cs +++ b/Tests/SuperLinq.Test/AtMostTest.cs @@ -31,7 +31,7 @@ public void AtMostWithEmptySequenceHasAtMostOneElement(IDisposableEnumerable seq) { using (seq) @@ -39,7 +39,7 @@ public void AtMostWithSingleElementHasAtMostZeroElements(IDisposableEnumerable seq) { using (seq) @@ -47,7 +47,7 @@ public void AtMostWithSingleElementHasAtMostOneElement(IDisposableEnumerable seq) { using (seq) @@ -55,7 +55,7 @@ public void AtMostWithSingleElementHasAtMostManyElements(IDisposableEnumerable seq) { using (seq) @@ -63,7 +63,7 @@ public void AtMostWithManyElementsHasAtMostZeroElements(IDisposableEnumerable seq) { using (seq) @@ -71,7 +71,7 @@ public void AtMostWithManyElementsHasAtMostOneElement(IDisposableEnumerable } [Theory] - [MemberData(nameof(GetSequences), new int[] { 1, 2, 3, })] + [MemberData(nameof(GetSequences), new int[] { 1, 2, 3 })] public void AtMostWithManyElementsHasAtMostManyElement(IDisposableEnumerable seq) { using (seq) diff --git a/Tests/SuperLinq.Test/BatchTest.cs b/Tests/SuperLinq.Test/BatchTest.cs index 1371f9c2b..1c3d6ea60 100644 --- a/Tests/SuperLinq.Test/BatchTest.cs +++ b/Tests/SuperLinq.Test/BatchTest.cs @@ -109,10 +109,11 @@ public enum BatchMethod private static IEnumerable GetBatchTestSequences(IEnumerable source) { foreach (var seq in source.GetListSequences()) - yield return new object[] { seq, BatchMethod.Traditional, }; - yield return new object[] { source.AsTestingSequence(), BatchMethod.BufferSize, }; - yield return new object[] { source.AsTestingSequence(), BatchMethod.BufferArray, }; - yield return new object[] { source.AsTestingSequence(), BatchMethod.BufferSizeArray, }; + yield return new object[] { seq, BatchMethod.Traditional }; + + yield return new object[] { source.AsTestingSequence(), BatchMethod.BufferSize }; + yield return new object[] { source.AsTestingSequence(), BatchMethod.BufferArray }; + yield return new object[] { source.AsTestingSequence(), BatchMethod.BufferSizeArray }; } private static IEnumerable> GetBatches( @@ -187,10 +188,10 @@ public void BatchSmallSequence(IDisposableEnumerable seq, BatchMethod bm) public static IEnumerable GetBreakingCollections(IEnumerable source) { - yield return new object[] { source.AsBreakingCollection(), BatchMethod.Traditional, }; - yield return new object[] { source.AsBreakingCollection(), BatchMethod.BufferSize, }; - yield return new object[] { source.AsBreakingCollection(), BatchMethod.BufferArray, }; - yield return new object[] { source.AsBreakingCollection(), BatchMethod.BufferSizeArray, }; + yield return new object[] { source.AsBreakingCollection(), BatchMethod.Traditional }; + yield return new object[] { source.AsBreakingCollection(), BatchMethod.BufferSize }; + yield return new object[] { source.AsBreakingCollection(), BatchMethod.BufferArray }; + yield return new object[] { source.AsBreakingCollection(), BatchMethod.BufferSizeArray }; } [Theory] @@ -223,7 +224,7 @@ public void BatchWithCollectionSmallerThanBatchSize(IDisposableEnumerable s [InlineData(BatchMethod.BufferSizeArray)] public void BatchCollectionSizeNotEvaluatedEarly(BatchMethod bm) { - var list = new List() { 1, 2, 3, }; + var list = new List() { 1, 2, 3 }; var result = GetBatches(list, bm, 3); list.Add(4); result.AssertCount(2).Consume(); diff --git a/Tests/SuperLinq.Test/BreakingList.cs b/Tests/SuperLinq.Test/BreakingList.cs index bf20f1430..937bb6584 100644 --- a/Tests/SuperLinq.Test/BreakingList.cs +++ b/Tests/SuperLinq.Test/BreakingList.cs @@ -21,6 +21,7 @@ public T this[int index] { if (index < 0 || index >= _list.Count) Assert.Fail("LINQ Operators should prevent this from happening."); + return _list[index]; } diff --git a/Tests/SuperLinq.Test/CartesianTest.cs b/Tests/SuperLinq.Test/CartesianTest.cs index 94b54d008..5a7c5bec7 100644 --- a/Tests/SuperLinq.Test/CartesianTest.cs +++ b/Tests/SuperLinq.Test/CartesianTest.cs @@ -124,6 +124,7 @@ public void TestCartesianProductCombinations() // ensure that all "cells" were visited by the cartesian product foreach (var coord in result) expectedSet[coord.A][coord.B] = true; + Assert.True(expectedSet.SelectMany(SuperEnumerable.Identity).All(SuperEnumerable.Identity)); } diff --git a/Tests/SuperLinq.Test/CatchTest.cs b/Tests/SuperLinq.Test/CatchTest.cs index eabb6d914..3948b5cc9 100644 --- a/Tests/SuperLinq.Test/CatchTest.cs +++ b/Tests/SuperLinq.Test/CatchTest.cs @@ -14,7 +14,7 @@ public void CatchIsLazy() [Fact] public void CatchThrowsDelayedExceptionOnNullSource() { - var seq = SuperEnumerable.Catch(new IEnumerable[] { null!, }); + var seq = SuperEnumerable.Catch(new IEnumerable[] { null! }); _ = Assert.Throws(seq.Consume); } @@ -87,7 +87,7 @@ public void CatchMultipleSequencesWithNoExceptionOnSequence(int sequenceNumber) using var ts4 = (cnt++ == sequenceNumber ? Enumerable.Range(1, 10) : SeqExceptionAt(5)).AsTestingSequence(); using var ts5 = (cnt++ == sequenceNumber ? Enumerable.Range(1, 10) : SeqExceptionAt(5)).AsTestingSequence(); - using var seq = new[] { ts1, ts2, ts3, ts4, ts5, }.AsTestingSequence(); + using var seq = new[] { ts1, ts2, ts3, ts4, ts5 }.AsTestingSequence(); var result = seq.Catch(); diff --git a/Tests/SuperLinq.Test/CompareCountTest.cs b/Tests/SuperLinq.Test/CompareCountTest.cs index f082ad5bc..d190e7d82 100644 --- a/Tests/SuperLinq.Test/CompareCountTest.cs +++ b/Tests/SuperLinq.Test/CompareCountTest.cs @@ -14,7 +14,7 @@ from s in GetTestSequenceKinds( Enumerable.Range(1, e.Count1), Enumerable.Range(1, e.Count2), (xs, ys) => new { First = xs, Second = ys }) - select new object[] { s.First.Data, s.Second.Data, e.Comparison, }; + select new object[] { s.First.Data, s.Second.Data, e.Comparison }; [Theory, MemberData(nameof(CompareCountData))] public void CompareCount(IEnumerable xs, IEnumerable ys, int expected) diff --git a/Tests/SuperLinq.Test/CopyToTest.cs b/Tests/SuperLinq.Test/CopyToTest.cs index 4a4a41888..9e84302d4 100644 --- a/Tests/SuperLinq.Test/CopyToTest.cs +++ b/Tests/SuperLinq.Test/CopyToTest.cs @@ -93,7 +93,7 @@ public void CopiesDataToSpan() span.ToArray().AssertSequenceEqual(1, 2, 0, 0); Assert.Equal(1, cnt); - cnt = new[] { 3, 4, }.AsEnumerable().CopyTo(span[2..]); + cnt = new[] { 3, 4 }.AsEnumerable().CopyTo(span[2..]); span.ToArray().AssertSequenceEqual(1, 2, 3, 4); Assert.Equal(2, cnt); } @@ -116,7 +116,7 @@ public void CopiesDataToArray() array.AssertSequenceEqual(1, 2, 3, 0); Assert.Equal(1, cnt); - cnt = new[] { 4, }.AsEnumerable().CopyTo(array, 3); + cnt = new[] { 4 }.AsEnumerable().CopyTo(array, 3); array.AssertSequenceEqual(1, 2, 3, 4); Assert.Equal(1, cnt); } @@ -126,7 +126,7 @@ public void CopiesDataToList() { var list = new List(); - var cnt = new[] { 1, }.AsEnumerable().CopyTo(list); + var cnt = new[] { 1 }.AsEnumerable().CopyTo(list); list.AssertSequenceEqual(1); Assert.Equal(1, cnt); diff --git a/Tests/SuperLinq.Test/CountBetweenTest.cs b/Tests/SuperLinq.Test/CountBetweenTest.cs index c4746a321..1a144e235 100644 --- a/Tests/SuperLinq.Test/CountBetweenTest.cs +++ b/Tests/SuperLinq.Test/CountBetweenTest.cs @@ -29,7 +29,7 @@ public static IEnumerable GetSequences(IEnumerable seq) => .Select(x => new object[] { x }); [Theory] - [MemberData(nameof(GetSequences), new int[] { 1, })] + [MemberData(nameof(GetSequences), new int[] { 1 })] public void CountBetweenWithMaxEqualsMin(IDisposableEnumerable seq) { using (seq) diff --git a/Tests/SuperLinq.Test/CountDownTest.cs b/Tests/SuperLinq.Test/CountDownTest.cs index 1c6cefdb2..3a9296660 100644 --- a/Tests/SuperLinq.Test/CountDownTest.cs +++ b/Tests/SuperLinq.Test/CountDownTest.cs @@ -28,9 +28,7 @@ public static IEnumerable GetTheoryData() : Enumerable.Range(0, 5).Select(x => (int?)x).Reverse(); foreach (var seq in xs.GetAllSequences()) - { - yield return new object[] { seq, i, xs.EquiZip(countdown), }; - } + yield return new object[] { seq, i, xs.EquiZip(countdown) }; } } diff --git a/Tests/SuperLinq.Test/DensePartialSortByTest.cs b/Tests/SuperLinq.Test/DensePartialSortByTest.cs index 7b5e6a396..1d1d2728f 100644 --- a/Tests/SuperLinq.Test/DensePartialSortByTest.cs +++ b/Tests/SuperLinq.Test/DensePartialSortByTest.cs @@ -21,7 +21,7 @@ public void DensePartialSortBy() var sorted = xs.DensePartialSortBy(3, e => e.Key); sorted.Select(e => e.Value).AssertSequenceEqual( - ns.Take(3).SelectMany(x => new[] { x, x, })); + ns.Take(3).SelectMany(x => new[] { x, x })); } [Theory] @@ -44,7 +44,7 @@ public void DensePartialSortWithOrder(OrderByDirection direction) ns = ns.Reverse(); sorted.Select(e => e.Value).AssertSequenceEqual( - ns.Take(3).SelectMany(x => new[] { x, x, })); + ns.Take(3).SelectMany(x => new[] { x, x })); } [Fact] diff --git a/Tests/SuperLinq.Test/DenseRankTest.cs b/Tests/SuperLinq.Test/DenseRankTest.cs index ccf13bf7c..c3185455b 100644 --- a/Tests/SuperLinq.Test/DenseRankTest.cs +++ b/Tests/SuperLinq.Test/DenseRankTest.cs @@ -25,7 +25,7 @@ public void TestDenseRankByIsLazy() public static IEnumerable GetSimpleSequences() => Enumerable.Repeat(1, 10) .GetTestingSequence(maxEnumerations: 2) - .Select(x => new object[] { x, }); + .Select(x => new object[] { x }); /// /// Verify that calling DenseRank with null comparer results in a sequence @@ -73,7 +73,7 @@ public static IEnumerable GetDescendingIntSequences() => Enumerable.Range(456, 100) .Reverse() .GetTestingSequence(maxEnumerations: 2) - .Select(x => new object[] { x, }); + .Select(x => new object[] { x }); /// /// Verify that calling DenseRank with null comparer on a source in reverse order @@ -104,7 +104,7 @@ public void TestRankDescendingSequence(IDisposableEnumerable seq) public static IEnumerable GetAscendingIntSequences() => Enumerable.Range(456, 100) .GetTestingSequence(maxEnumerations: 2) - .Select(x => new object[] { x, }); + .Select(x => new object[] { x }); /// /// Verify that calling DenseRank with null comparer on a source in ascending order @@ -160,7 +160,7 @@ public static IEnumerable GetGroupedSequences() => .Concat(Enumerable.Range(0, 10)) .Concat(Enumerable.Range(0, 10)) .GetTestingSequence(maxEnumerations: 2) - .Select(x => new object[] { x, }); + .Select(x => new object[] { x }); /// /// Verify that the rank of equivalent items in a sequence is the same. @@ -205,7 +205,7 @@ public static IEnumerable GetPersonSequences1() => new Person(Name: "Jes", Age: 11, ExpectedRank: 1), } .GetTestingSequence(maxEnumerations: 2) - .Select(x => new object[] { x, }); + .Select(x => new object[] { x }); public static IEnumerable GetPersonSequences2() => new[] @@ -220,7 +220,7 @@ public static IEnumerable GetPersonSequences2() => new Person(Name: "Jim", Age: 28, ExpectedRank: 3), } .GetTestingSequence(maxEnumerations: 2) - .Select(x => new object[] { x, }); + .Select(x => new object[] { x }); /// /// Verify that we can rank items by an arbitrary key produced from the item. @@ -251,7 +251,7 @@ public static IEnumerable GetDateTimeSequences() => Enumerable.Range(1, 10) .Select(x => new DateTime(2010, x, 20 - x)) .GetTestingSequence(maxEnumerations: 2) - .Select(x => new object[] { x, }); + .Select(x => new object[] { x }); /// /// Verify that Rank can use a custom comparer diff --git a/Tests/SuperLinq.Test/DuplicatesTest.cs b/Tests/SuperLinq.Test/DuplicatesTest.cs index 0397ff499..7433ce07f 100644 --- a/Tests/SuperLinq.Test/DuplicatesTest.cs +++ b/Tests/SuperLinq.Test/DuplicatesTest.cs @@ -9,9 +9,9 @@ public void DuplicatesIsLazy() } [Theory] - [InlineData(new int[] { 1, 2, 3, }, new int[] { })] - [InlineData(new int[] { 1, 2, 1, 3, 1, 2, 1, }, new int[] { 1, 2, })] - [InlineData(new int[] { 3, 3, 2, 2, 1, 1, }, new int[] { 3, 2, 1, })] + [InlineData(new int[] { 1, 2, 3 }, new int[] { })] + [InlineData(new int[] { 1, 2, 1, 3, 1, 2, 1 }, new int[] { 1, 2 })] + [InlineData(new int[] { 3, 3, 2, 2, 1, 1 }, new int[] { 3, 2, 1 })] public void DuplicatesBehavior(IEnumerable source, IEnumerable expected) { using var ts = source.AsTestingSequence(); @@ -38,13 +38,13 @@ public static IEnumerable GetStringParameters() { new string[] { "foo", "FOO", "bar", "qux" }, StringComparer.OrdinalIgnoreCase, - new string[] { "FOO", }, + new string[] { "FOO" }, }; yield return new object[] { new string[] { "Bar", "foo", "FOO", "bar", "qux" }, StringComparer.OrdinalIgnoreCase, - new string[] { "FOO", "bar", }, + new string[] { "FOO", "bar" }, }; } diff --git a/Tests/SuperLinq.Test/ElementAtTest.cs b/Tests/SuperLinq.Test/ElementAtTest.cs index 923add747..c52d5db72 100644 --- a/Tests/SuperLinq.Test/ElementAtTest.cs +++ b/Tests/SuperLinq.Test/ElementAtTest.cs @@ -21,7 +21,7 @@ where x > int.MinValue [Fact] public void SameResultsRepeatCallsStringQuery() { - var q = Enumerable.Repeat(from x in new[] { "!@#$%^", "C", "AAA", "", "Calling Twice", "SoS", string.Empty } + var q = Enumerable.Repeat(from x in new[] { "!@#$%^", "C", "AAA", "", "Calling Twice", "SoS", "" } where !string.IsNullOrEmpty(x) select x, 3).ToArray(); diff --git a/Tests/SuperLinq.Test/EvaluateTest.cs b/Tests/SuperLinq.Test/EvaluateTest.cs index 9c64e8878..d89bad291 100644 --- a/Tests/SuperLinq.Test/EvaluateTest.cs +++ b/Tests/SuperLinq.Test/EvaluateTest.cs @@ -1,4 +1,4 @@ -namespace Test; +namespace Test; public sealed class EvaluateTest { @@ -29,7 +29,7 @@ public void TestEvaluateInvokesMethodsMultipleTimes() var evals = 0; var factories = new Func[] { - () => { evals++; return -2; }, + () => { evals++; return -2; }, }; var results = factories.Evaluate(); diff --git a/Tests/SuperLinq.Test/ExactlyTest.cs b/Tests/SuperLinq.Test/ExactlyTest.cs index e001ad629..f20d93ce9 100644 --- a/Tests/SuperLinq.Test/ExactlyTest.cs +++ b/Tests/SuperLinq.Test/ExactlyTest.cs @@ -31,7 +31,7 @@ public void ExactlyWithEmptySequenceHasExactlyOneElement(IDisposableEnumerable seq) { using (seq) @@ -39,7 +39,7 @@ public void ExactlyWithSingleElementHasExactlyZeroElements(IDisposableEnumerable } [Theory] - [MemberData(nameof(GetSequences), new int[] { 1, })] + [MemberData(nameof(GetSequences), new int[] { 1 })] public void ExactlyWithSingleElementHasExactlyOneElements(IDisposableEnumerable seq) { using (seq) @@ -47,7 +47,7 @@ public void ExactlyWithSingleElementHasExactlyOneElements(IDisposableEnumerable< } [Theory] - [MemberData(nameof(GetSequences), new int[] { 1, })] + [MemberData(nameof(GetSequences), new int[] { 1 })] public void ExactlyWithSingleElementHasExactlyTwoElements(IDisposableEnumerable seq) { using (seq) @@ -55,7 +55,7 @@ public void ExactlyWithSingleElementHasExactlyTwoElements(IDisposableEnumerable< } [Theory] - [MemberData(nameof(GetSequences), new int[] { 1, 2, 3, })] + [MemberData(nameof(GetSequences), new int[] { 1, 2, 3 })] public void ExactlyWithThreeElementsHasExactlyTwoElements(IDisposableEnumerable seq) { using (seq) @@ -63,7 +63,7 @@ public void ExactlyWithThreeElementsHasExactlyTwoElements(IDisposableEnumerable< } [Theory] - [MemberData(nameof(GetSequences), new int[] { 1, 2, 3, })] + [MemberData(nameof(GetSequences), new int[] { 1, 2, 3 })] public void ExactlyWithThreeElementsHasExactlyThreeElements(IDisposableEnumerable seq) { using (seq) @@ -71,7 +71,7 @@ public void ExactlyWithThreeElementsHasExactlyThreeElements(IDisposableEnumerabl } [Theory] - [MemberData(nameof(GetSequences), new int[] { 1, 2, 3, })] + [MemberData(nameof(GetSequences), new int[] { 1, 2, 3 })] public void ExactlyWithThreeElementsHasExactlyFourElements(IDisposableEnumerable seq) { using (seq) diff --git a/Tests/SuperLinq.Test/FlattenTest.cs b/Tests/SuperLinq.Test/FlattenTest.cs index b72593ba1..5ce192522 100644 --- a/Tests/SuperLinq.Test/FlattenTest.cs +++ b/Tests/SuperLinq.Test/FlattenTest.cs @@ -334,7 +334,7 @@ public void FlattenSelectorWithTree() private sealed class Series { - public string Name { get; init; } = string.Empty; + public string Name { get; init; } = ""; public Attribute[] Attributes { get; init; } = []; } diff --git a/Tests/SuperLinq.Test/FoldTest.cs b/Tests/SuperLinq.Test/FoldTest.cs index 887d76768..53c69046a 100644 --- a/Tests/SuperLinq.Test/FoldTest.cs +++ b/Tests/SuperLinq.Test/FoldTest.cs @@ -28,21 +28,21 @@ public void Fold() { const string Alphabet = "abcdefghijklmnopqrstuvwxyz"; - using (var ts = Alphabet.Take(1).AsTestingSequence()) Assert.Equal("a", ts.Fold(a => string.Join(string.Empty, a))); - using (var ts = Alphabet.Take(2).AsTestingSequence()) Assert.Equal("ab", ts.Fold((a, b) => string.Join(string.Empty, a, b))); - using (var ts = Alphabet.Take(3).AsTestingSequence()) Assert.Equal("abc", ts.Fold((a, b, c) => string.Join(string.Empty, a, b, c))); - using (var ts = Alphabet.Take(4).AsTestingSequence()) Assert.Equal("abcd", ts.Fold((a, b, c, d) => string.Join(string.Empty, a, b, c, d))); - using (var ts = Alphabet.Take(5).AsTestingSequence()) Assert.Equal("abcde", ts.Fold((a, b, c, d, e) => string.Join(string.Empty, a, b, c, d, e))); - using (var ts = Alphabet.Take(6).AsTestingSequence()) Assert.Equal("abcdef", ts.Fold((a, b, c, d, e, f) => string.Join(string.Empty, a, b, c, d, e, f))); - using (var ts = Alphabet.Take(7).AsTestingSequence()) Assert.Equal("abcdefg", ts.Fold((a, b, c, d, e, f, g) => string.Join(string.Empty, a, b, c, d, e, f, g))); - using (var ts = Alphabet.Take(8).AsTestingSequence()) Assert.Equal("abcdefgh", ts.Fold((a, b, c, d, e, f, g, h) => string.Join(string.Empty, a, b, c, d, e, f, g, h))); - using (var ts = Alphabet.Take(9).AsTestingSequence()) Assert.Equal("abcdefghi", ts.Fold((a, b, c, d, e, f, g, h, i) => string.Join(string.Empty, a, b, c, d, e, f, g, h, i))); - using (var ts = Alphabet.Take(10).AsTestingSequence()) Assert.Equal("abcdefghij", ts.Fold((a, b, c, d, e, f, g, h, i, j) => string.Join(string.Empty, a, b, c, d, e, f, g, h, i, j))); - using (var ts = Alphabet.Take(11).AsTestingSequence()) Assert.Equal("abcdefghijk", ts.Fold((a, b, c, d, e, f, g, h, i, j, k) => string.Join(string.Empty, a, b, c, d, e, f, g, h, i, j, k))); - using (var ts = Alphabet.Take(12).AsTestingSequence()) Assert.Equal("abcdefghijkl", ts.Fold((a, b, c, d, e, f, g, h, i, j, k, l) => string.Join(string.Empty, a, b, c, d, e, f, g, h, i, j, k, l))); - using (var ts = Alphabet.Take(13).AsTestingSequence()) Assert.Equal("abcdefghijklm", ts.Fold((a, b, c, d, e, f, g, h, i, j, k, l, m) => string.Join(string.Empty, a, b, c, d, e, f, g, h, i, j, k, l, m))); - using (var ts = Alphabet.Take(14).AsTestingSequence()) Assert.Equal("abcdefghijklmn", ts.Fold((a, b, c, d, e, f, g, h, i, j, k, l, m, n) => string.Join(string.Empty, a, b, c, d, e, f, g, h, i, j, k, l, m, n))); - using (var ts = Alphabet.Take(15).AsTestingSequence()) Assert.Equal("abcdefghijklmno", ts.Fold((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) => string.Join(string.Empty, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))); - using (var ts = Alphabet.Take(16).AsTestingSequence()) Assert.Equal("abcdefghijklmnop", ts.Fold((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) => string.Join(string.Empty, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p))); + using (var ts = Alphabet.Take(1).AsTestingSequence()) Assert.Equal("a", ts.Fold(a => string.Join("", a))); + using (var ts = Alphabet.Take(2).AsTestingSequence()) Assert.Equal("ab", ts.Fold((a, b) => string.Join("", a, b))); + using (var ts = Alphabet.Take(3).AsTestingSequence()) Assert.Equal("abc", ts.Fold((a, b, c) => string.Join("", a, b, c))); + using (var ts = Alphabet.Take(4).AsTestingSequence()) Assert.Equal("abcd", ts.Fold((a, b, c, d) => string.Join("", a, b, c, d))); + using (var ts = Alphabet.Take(5).AsTestingSequence()) Assert.Equal("abcde", ts.Fold((a, b, c, d, e) => string.Join("", a, b, c, d, e))); + using (var ts = Alphabet.Take(6).AsTestingSequence()) Assert.Equal("abcdef", ts.Fold((a, b, c, d, e, f) => string.Join("", a, b, c, d, e, f))); + using (var ts = Alphabet.Take(7).AsTestingSequence()) Assert.Equal("abcdefg", ts.Fold((a, b, c, d, e, f, g) => string.Join("", a, b, c, d, e, f, g))); + using (var ts = Alphabet.Take(8).AsTestingSequence()) Assert.Equal("abcdefgh", ts.Fold((a, b, c, d, e, f, g, h) => string.Join("", a, b, c, d, e, f, g, h))); + using (var ts = Alphabet.Take(9).AsTestingSequence()) Assert.Equal("abcdefghi", ts.Fold((a, b, c, d, e, f, g, h, i) => string.Join("", a, b, c, d, e, f, g, h, i))); + using (var ts = Alphabet.Take(10).AsTestingSequence()) Assert.Equal("abcdefghij", ts.Fold((a, b, c, d, e, f, g, h, i, j) => string.Join("", a, b, c, d, e, f, g, h, i, j))); + using (var ts = Alphabet.Take(11).AsTestingSequence()) Assert.Equal("abcdefghijk", ts.Fold((a, b, c, d, e, f, g, h, i, j, k) => string.Join("", a, b, c, d, e, f, g, h, i, j, k))); + using (var ts = Alphabet.Take(12).AsTestingSequence()) Assert.Equal("abcdefghijkl", ts.Fold((a, b, c, d, e, f, g, h, i, j, k, l) => string.Join("", a, b, c, d, e, f, g, h, i, j, k, l))); + using (var ts = Alphabet.Take(13).AsTestingSequence()) Assert.Equal("abcdefghijklm", ts.Fold((a, b, c, d, e, f, g, h, i, j, k, l, m) => string.Join("", a, b, c, d, e, f, g, h, i, j, k, l, m))); + using (var ts = Alphabet.Take(14).AsTestingSequence()) Assert.Equal("abcdefghijklmn", ts.Fold((a, b, c, d, e, f, g, h, i, j, k, l, m, n) => string.Join("", a, b, c, d, e, f, g, h, i, j, k, l, m, n))); + using (var ts = Alphabet.Take(15).AsTestingSequence()) Assert.Equal("abcdefghijklmno", ts.Fold((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) => string.Join("", a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))); + using (var ts = Alphabet.Take(16).AsTestingSequence()) Assert.Equal("abcdefghijklmnop", ts.Fold((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) => string.Join("", a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p))); } } diff --git a/Tests/SuperLinq.Test/FullOuterJoinTest.cs b/Tests/SuperLinq.Test/FullOuterJoinTest.cs index af87d0997..0f4c26f69 100644 --- a/Tests/SuperLinq.Test/FullOuterJoinTest.cs +++ b/Tests/SuperLinq.Test/FullOuterJoinTest.cs @@ -2,7 +2,7 @@ namespace Test; -public enum JoinOperation { None, Loop, Hash, Merge, } +public enum JoinOperation { None, Loop, Hash, Merge } public sealed class FullOuterJoinTest { @@ -22,7 +22,7 @@ public sealed class FullOuterJoinTest }; public static IEnumerable GetFullOuterJoins() => - new[] { Hash, Merge, }.Cartesian(new[] { false, true, }, (x, y) => new object[] { x, y, }); + new[] { Hash, Merge }.Cartesian(new[] { false, true }, (x, y) => new object[] { x, y }); [Theory, MemberData(nameof(GetFullOuterJoins))] public void FullOuterJoinIsLazy(JoinOperation op, bool passProjectors) diff --git a/Tests/SuperLinq.Test/HasDuplicatesTest.cs b/Tests/SuperLinq.Test/HasDuplicatesTest.cs index dd6d2f4a7..35447f4af 100644 --- a/Tests/SuperLinq.Test/HasDuplicatesTest.cs +++ b/Tests/SuperLinq.Test/HasDuplicatesTest.cs @@ -12,9 +12,9 @@ public void DuplicatesDoesNotEnumerateUnnecessarily() } [Theory] - [InlineData(new int[] { 1, 2, 3, }, false)] - [InlineData(new int[] { 1, 2, 1, 3, 1, 2, 1, }, true)] - [InlineData(new int[] { 3, 3, 2, 2, 1, 1, }, true)] + [InlineData(new int[] { 1, 2, 3 }, false)] + [InlineData(new int[] { 1, 2, 1, 3, 1, 2, 1 }, true)] + [InlineData(new int[] { 3, 3, 2, 2, 1, 1 }, true)] public void DuplicatesBehavior(IEnumerable source, bool expected) { using var ts = source.AsTestingSequence(); diff --git a/Tests/SuperLinq.Test/InnerJoinTest.cs b/Tests/SuperLinq.Test/InnerJoinTest.cs index 260d642ec..20be9763f 100644 --- a/Tests/SuperLinq.Test/InnerJoinTest.cs +++ b/Tests/SuperLinq.Test/InnerJoinTest.cs @@ -22,7 +22,7 @@ public sealed class InnerJoinTest }; public static IEnumerable GetInnerJoins() => - new[] { Loop, Hash, Merge, }.Cartesian(new[] { false, true, }, (x, y) => new object[] { x, y, }); + new[] { Loop, Hash, Merge }.Cartesian(new[] { false, true }, (x, y) => new object[] { x, y }); [Theory, MemberData(nameof(GetInnerJoins))] public void InnerJoinIsLazy(JoinOperation op, bool passProjectors) diff --git a/Tests/SuperLinq.Test/LagTest.cs b/Tests/SuperLinq.Test/LagTest.cs index 285e73a51..d594041ba 100644 --- a/Tests/SuperLinq.Test/LagTest.cs +++ b/Tests/SuperLinq.Test/LagTest.cs @@ -118,7 +118,7 @@ public void TestLagPassesCorrectLagValuesOffsetBy2(IDisposableEnumerable se public static IEnumerable GetStringSequences() => Seq("foo", "bar", "baz", "qux") .GetListSequences() - .Select(x => new object[] { x, }); + .Select(x => new object[] { x }); [Theory] [MemberData(nameof(GetStringSequences))] @@ -141,10 +141,10 @@ public void TestLagWithNonNullableReferences(IDisposableEnumerable seq) { using (seq) { - var result = seq.Lag(2, string.Empty, (a, b) => new { A = a, B = b }); + var result = seq.Lag(2, "", (a, b) => new { A = a, B = b }); result.AssertSequenceEqual( - new { A = "foo", B = string.Empty, }, - new { A = "bar", B = string.Empty, }, + new { A = "foo", B = "" }, + new { A = "bar", B = "" }, new { A = "baz", B = "foo" }, new { A = "qux", B = "bar" }); } diff --git a/Tests/SuperLinq.Test/LeadTest.cs b/Tests/SuperLinq.Test/LeadTest.cs index 6b04bc235..d050ca9a5 100644 --- a/Tests/SuperLinq.Test/LeadTest.cs +++ b/Tests/SuperLinq.Test/LeadTest.cs @@ -121,7 +121,7 @@ public void TestLeadPassesCorrectValueOffsetBy2(IDisposableEnumerable seq) public static IEnumerable GetStringSequences() => Seq("foo", "bar", "baz", "qux") .GetListSequences() - .Select(x => new object[] { x, }); + .Select(x => new object[] { x }); [Theory] [MemberData(nameof(GetStringSequences))] @@ -144,12 +144,12 @@ public void TestLagWithNonNullableReferences(IDisposableEnumerable seq) { using (seq) { - var result = seq.Lead(2, string.Empty, (a, b) => new { A = a, B = b }); + var result = seq.Lead(2, "", (a, b) => new { A = a, B = b }); result.AssertSequenceEqual( new { A = "foo", B = "baz" }, new { A = "bar", B = "qux" }, - new { A = "baz", B = string.Empty }, - new { A = "qux", B = string.Empty }); + new { A = "baz", B = "" }, + new { A = "qux", B = "" }); } } diff --git a/Tests/SuperLinq.Test/LeftOuterJoin.cs b/Tests/SuperLinq.Test/LeftOuterJoin.cs index 1963ac96c..f2f508e01 100644 --- a/Tests/SuperLinq.Test/LeftOuterJoin.cs +++ b/Tests/SuperLinq.Test/LeftOuterJoin.cs @@ -22,7 +22,7 @@ public sealed class LeftOuterJoinTest }; public static IEnumerable GetLeftOuterJoins() => - new[] { Loop, Hash, Merge, }.Cartesian(new[] { false, true, }, (x, y) => new object[] { x, y, }); + new[] { Loop, Hash, Merge }.Cartesian(new[] { false, true }, (x, y) => new object[] { x, y }); [Theory, MemberData(nameof(GetLeftOuterJoins))] public void LeftOuterJoinIsLazy(JoinOperation op, bool passProjectors) diff --git a/Tests/SuperLinq.Test/MemoizeTest.cs b/Tests/SuperLinq.Test/MemoizeTest.cs index 7b71f3554..beef311d5 100644 --- a/Tests/SuperLinq.Test/MemoizeTest.cs +++ b/Tests/SuperLinq.Test/MemoizeTest.cs @@ -85,9 +85,7 @@ static IEnumerable InnerForEach(IEnumerable source) yield return "enter last loop"; //consume 1-10 (all item were already cached) foreach (var k in source) - { yield return k; - } yield return "exit last loop"; } @@ -287,6 +285,7 @@ public void MemoizeIteratorRethrowsErrorDuringIterationStartToAllIteratorsUntilR using (var r1 = buffer.Read()) using (var r2 = buffer.Read()) Guard.IsTrue(r1.Read() == r2.Read()); + Assert.Equal(1, buffer.Count); } diff --git a/Tests/SuperLinq.Test/MoveTest.cs b/Tests/SuperLinq.Test/MoveTest.cs index 590946d61..6dca66df5 100644 --- a/Tests/SuperLinq.Test/MoveTest.cs +++ b/Tests/SuperLinq.Test/MoveTest.cs @@ -73,7 +73,7 @@ public void MoveWithSequenceShorterThanToIndex(int length, int fromIndex, int co public static IEnumerable MoveWithSequenceShorterThanToIndexSource() => Enumerable.Range(10, 10 + 5) - .Select(toIndex => new object[] { 10, 5, 2, toIndex, }); + .Select(toIndex => new object[] { 10, 5, 2, toIndex }); [Fact] public void MoveIsRepeatable() diff --git a/Tests/SuperLinq.Test/OnErrorResumeNextTest.cs b/Tests/SuperLinq.Test/OnErrorResumeNextTest.cs index c1b31fcb5..a71f9e3fa 100644 --- a/Tests/SuperLinq.Test/OnErrorResumeNextTest.cs +++ b/Tests/SuperLinq.Test/OnErrorResumeNextTest.cs @@ -43,7 +43,7 @@ public void OnErrorResumeNextMultipleSequencesWithNoExceptionOnSequence(int sequ using var ts4 = (cnt++ == sequenceNumber ? Enumerable.Range(1, 10) : SeqExceptionAt(5)).AsTestingSequence(); using var ts5 = (cnt++ == sequenceNumber ? Enumerable.Range(1, 10) : SeqExceptionAt(5)).AsTestingSequence(); - using var seq = new[] { ts1, ts2, ts3, ts4, ts5, }.AsTestingSequence(); + using var seq = new[] { ts1, ts2, ts3, ts4, ts5 }.AsTestingSequence(); var result = seq.OnErrorResumeNext(); diff --git a/Tests/SuperLinq.Test/OrderByTest.cs b/Tests/SuperLinq.Test/OrderByTest.cs index 41e2b2d97..dcba067db 100644 --- a/Tests/SuperLinq.Test/OrderByTest.cs +++ b/Tests/SuperLinq.Test/OrderByTest.cs @@ -65,12 +65,12 @@ public void TestThenBySelectorPreserved() { var sequence = new[] { - new { A = 2, B = 0, }, - new { A = 1, B = 5, }, - new { A = 2, B = 2, }, - new { A = 1, B = 3, }, - new { A = 1, B = 4, }, - new { A = 2, B = 1, }, + new { A = 2, B = 0 }, + new { A = 1, B = 5 }, + new { A = 2, B = 2 }, + new { A = 1, B = 3 }, + new { A = 1, B = 4 }, + new { A = 2, B = 1 }, }; var resultA1 = sequence @@ -104,12 +104,12 @@ public void TestThenByComparerPreserved() { var sequence = new[] { - new { A = "2", B = "0", }, - new { A = "1", B = "5", }, - new { A = "2", B = "2", }, - new { A = "1", B = "3", }, - new { A = "1", B = "4", }, - new { A = "2", B = "1", }, + new { A = "2", B = "0" }, + new { A = "1", B = "5" }, + new { A = "2", B = "2" }, + new { A = "1", B = "3" }, + new { A = "1", B = "4" }, + new { A = "2", B = "1" }, }; var comparer = Comparer.Create( diff --git a/Tests/SuperLinq.Test/PadStartTest.cs b/Tests/SuperLinq.Test/PadStartTest.cs index c9e996acf..5f36a40ea 100644 --- a/Tests/SuperLinq.Test/PadStartTest.cs +++ b/Tests/SuperLinq.Test/PadStartTest.cs @@ -20,7 +20,7 @@ public void PadStartIsLazy() public static IEnumerable GetIntSequences() => Seq(123, 456, 789) .GetAllSequences() - .Select(x => new object[] { x, }); + .Select(x => new object[] { x }); [Theory] [MemberData(nameof(GetIntSequences))] @@ -122,7 +122,7 @@ public void PadStartNarrowListBehavior() public static IEnumerable GetCharSequences() => "hello".AsEnumerable() .GetAllSequences() - .Select(x => new object[] { x, }); + .Select(x => new object[] { x }); [Theory] [MemberData(nameof(GetCharSequences))] diff --git a/Tests/SuperLinq.Test/PadTest.cs b/Tests/SuperLinq.Test/PadTest.cs index ecdf7161c..4bd4f6966 100644 --- a/Tests/SuperLinq.Test/PadTest.cs +++ b/Tests/SuperLinq.Test/PadTest.cs @@ -20,7 +20,7 @@ public void PadIsLazy() public static IEnumerable GetIntSequences() => Seq(123, 456, 789) .GetAllSequences() - .Select(x => new object[] { x, }); + .Select(x => new object[] { x }); [Theory] [MemberData(nameof(GetIntSequences))] @@ -122,7 +122,7 @@ public void PadNarrowListBehavior() public static IEnumerable GetCharSequences() => "hello".AsEnumerable() .GetAllSequences() - .Select(x => new object[] { x, }); + .Select(x => new object[] { x }); [Theory] [MemberData(nameof(GetCharSequences))] diff --git a/Tests/SuperLinq.Test/PermutationsTest.cs b/Tests/SuperLinq.Test/PermutationsTest.cs index 4c071e755..ce896f4fd 100644 --- a/Tests/SuperLinq.Test/PermutationsTest.cs +++ b/Tests/SuperLinq.Test/PermutationsTest.cs @@ -25,7 +25,7 @@ public void TestCardinalityZeroPermutation() public static IEnumerable GetTooLongSequences() => Enumerable.Range(1, 22) .GetBreakingCollectionSequences() - .Select(x => new object[] { x, }); + .Select(x => new object[] { x }); [Theory] [MemberData(nameof(GetTooLongSequences))] @@ -198,9 +198,7 @@ public void TestPermutationsAreIndependent() for (var i = 0; i < permutedSets.Count; i++) { for (var j = i + 1; j < permutedSets.Count; j++) - { Guard.IsFalse(permutedSets[i].SequenceEqual(permutedSets[j])); - } } } } diff --git a/Tests/SuperLinq.Test/RankTest.cs b/Tests/SuperLinq.Test/RankTest.cs index b5a65bd8f..ebdf80c0a 100644 --- a/Tests/SuperLinq.Test/RankTest.cs +++ b/Tests/SuperLinq.Test/RankTest.cs @@ -25,7 +25,7 @@ public void TestRankByIsLazy() public static IEnumerable GetSimpleSequences() => Enumerable.Repeat(1, 10) .GetTestingSequence(maxEnumerations: 2) - .Select(x => new object[] { x, }); + .Select(x => new object[] { x }); /// /// Verify that calling Rank with null comparer results in a sequence @@ -73,7 +73,7 @@ public static IEnumerable GetDescendingIntSequences() => Enumerable.Range(456, 100) .Reverse() .GetTestingSequence(maxEnumerations: 2) - .Select(x => new object[] { x, }); + .Select(x => new object[] { x }); /// /// Verify that calling Rank with null comparer on a source in reverse order @@ -104,7 +104,7 @@ public void TestRankDescendingSequence(IDisposableEnumerable seq) public static IEnumerable GetAscendingIntSequences() => Enumerable.Range(456, 100) .GetTestingSequence(maxEnumerations: 2) - .Select(x => new object[] { x, }); + .Select(x => new object[] { x }); /// /// Verify that calling Rank with null comparer on a source in ascending order @@ -160,7 +160,7 @@ public static IEnumerable GetGroupedSequences() => .Concat(Enumerable.Range(0, 10)) .Concat(Enumerable.Range(0, 10)) .GetTestingSequence(maxEnumerations: 2) - .Select(x => new object[] { x, }); + .Select(x => new object[] { x }); /// /// Verify that the rank of equivalent items in a sequence is the same. @@ -205,7 +205,7 @@ public static IEnumerable GetPersonSequences1() => new Person(Name: "Jes", Age: 11, ExpectedRank: 1), } .GetTestingSequence(maxEnumerations: 2) - .Select(x => new object[] { x, }); + .Select(x => new object[] { x }); public static IEnumerable GetPersonSequences2() => new[] @@ -220,7 +220,7 @@ public static IEnumerable GetPersonSequences2() => new Person(Name: "Jim", Age: 28, ExpectedRank: 6), } .GetTestingSequence(maxEnumerations: 2) - .Select(x => new object[] { x, }); + .Select(x => new object[] { x }); /// /// Verify that we can rank items by an arbitrary key produced from the item. @@ -251,7 +251,7 @@ public static IEnumerable GetDateTimeSequences() => Enumerable.Range(1, 10) .Select(x => new DateTime(2010, x, 20 - x)) .GetTestingSequence(maxEnumerations: 2) - .Select(x => new object[] { x, }); + .Select(x => new object[] { x }); /// /// Verify that Rank can use a custom comparer diff --git a/Tests/SuperLinq.Test/ReplaceTest.cs b/Tests/SuperLinq.Test/ReplaceTest.cs index ecea6ab8f..399ac9a4d 100644 --- a/Tests/SuperLinq.Test/ReplaceTest.cs +++ b/Tests/SuperLinq.Test/ReplaceTest.cs @@ -26,7 +26,7 @@ public static IEnumerable Indices() => Enumerable.Range(0, 10) .SelectMany( _ => Enumerable.Range(1, 10).GetAllSequences(), - (i, s) => new object[] { i, s, }); + (i, s) => new object[] { i, s }); [Theory, MemberData(nameof(Indices))] public void ReplaceIntIndex(int index, IDisposableEnumerable seq) diff --git a/Tests/SuperLinq.Test/RightOuterJoin.cs b/Tests/SuperLinq.Test/RightOuterJoin.cs index 5d3f384df..9c98c6c1b 100644 --- a/Tests/SuperLinq.Test/RightOuterJoin.cs +++ b/Tests/SuperLinq.Test/RightOuterJoin.cs @@ -20,7 +20,7 @@ public sealed class RightOuterJoinTest }; public static IEnumerable GetRightOuterJoins() => - new[] { Hash, Merge, }.Cartesian(new[] { false, true, }, (x, y) => new object[] { x, y, }); + new[] { Hash, Merge }.Cartesian(new[] { false, true }, (x, y) => new object[] { x, y }); [Theory, MemberData(nameof(GetRightOuterJoins))] public void RightOuterJoinIsLazy(JoinOperation op, bool passProjectors) diff --git a/Tests/SuperLinq.Test/ScanRightTest.cs b/Tests/SuperLinq.Test/ScanRightTest.cs index af18c06bc..1e6acc23c 100644 --- a/Tests/SuperLinq.Test/ScanRightTest.cs +++ b/Tests/SuperLinq.Test/ScanRightTest.cs @@ -108,6 +108,6 @@ public void ScanRightSeedWithList() [Fact] public void ScanRightSeedIsLazy() { - _ = new BreakingSequence().ScanRight(string.Empty, BreakingFunc.Of()); + _ = new BreakingSequence().ScanRight("", BreakingFunc.Of()); } } diff --git a/Tests/SuperLinq.Test/SegmentTest.cs b/Tests/SuperLinq.Test/SegmentTest.cs index 4541b1338..2fc1ed63d 100644 --- a/Tests/SuperLinq.Test/SegmentTest.cs +++ b/Tests/SuperLinq.Test/SegmentTest.cs @@ -64,8 +64,10 @@ public void TestFirstSegmentNeverEmpty() { using (var sequence = Enumerable.Repeat(-1, 10).AsTestingSequence()) Assert.True(sequence.Segment(x => true).First().Any()); + using (var sequence = Enumerable.Repeat(-1, 10).AsTestingSequence()) Assert.True(sequence.Segment((x, index) => true).First().Any()); + using (var sequence = Enumerable.Repeat(-1, 10).AsTestingSequence()) Assert.True(sequence.Segment((x, prevX, index) => true).First().Any()); } @@ -78,8 +80,10 @@ public void TestSegmentationStartsWithSecondItem() { using (var sequence = TestingSequence.Of(0)) Assert.True(sequence.Segment(BreakingFunc.Of()).Any()); + using (var sequence = TestingSequence.Of(0)) Assert.True(sequence.Segment(BreakingFunc.Of()).Any()); + using (var sequence = TestingSequence.Of(0)) Assert.True(sequence.Segment(BreakingFunc.Of()).Any()); } @@ -131,7 +135,7 @@ from e in new[] // input sequence do not start with a segment start new { Source = Seq(1, 2, 3, 4, 5), Expected = Seq(Seq(1, 2), Seq(3, 4, 5)) }, } - select new object[] { e.Source, e.Expected, }; + select new object[] { e.Source, e.Expected }; [Theory] [MemberData(nameof(TestData))] diff --git a/Tests/SuperLinq.Test/SplitTest.cs b/Tests/SuperLinq.Test/SplitTest.cs index 5ff26c0f8..de2671e34 100644 --- a/Tests/SuperLinq.Test/SplitTest.cs +++ b/Tests/SuperLinq.Test/SplitTest.cs @@ -14,7 +14,7 @@ public void SplitWithComparer() { using var sequence = Enumerable.Range(1, 10).AsTestingSequence(); var result = sequence.Split(2, EqualityComparer.Create((x, y) => x % 2 == y % 2)); - result.AssertSequenceEqual(Enumerable.Range(1, 5).Select(x => new[] { (x * 2) - 1, })); + result.AssertSequenceEqual(Enumerable.Range(1, 5).Select(x => new[] { (x * 2) - 1 })); } [Fact] diff --git a/Tests/SuperLinq.Test/SubsetTest.cs b/Tests/SuperLinq.Test/SubsetTest.cs index 9f4bd606d..9107f18d9 100644 --- a/Tests/SuperLinq.Test/SubsetTest.cs +++ b/Tests/SuperLinq.Test/SubsetTest.cs @@ -28,7 +28,7 @@ public void TestNegativeSubsetSize() public static IEnumerable GetSubsetSequences() => Enumerable.Range(1, 10) .GetCollectionSequences() - .Select(x => new object?[] { x, }); + .Select(x => new object?[] { x }); /// /// Verify that requesting subsets larger than the original sequence length result in an exception. diff --git a/Tests/SuperLinq.Test/TakeTest.cs b/Tests/SuperLinq.Test/TakeTest.cs index 32760932b..75f80be0e 100644 --- a/Tests/SuperLinq.Test/TakeTest.cs +++ b/Tests/SuperLinq.Test/TakeTest.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. namespace Test; @@ -39,7 +39,7 @@ where x > int.MinValue [Fact] public void SameResultsRepeatCallsStringQuery() { - var q = from x in new[] { "!@#$%^", "C", "AAA", "", "Calling Twice", "SoS", string.Empty } + var q = from x in new[] { "!@#$%^", "C", "AAA", "", "Calling Twice", "SoS", "" } where !string.IsNullOrEmpty(x) select x; @@ -54,7 +54,7 @@ public void SameResultsRepeatCallsStringQuery() [Fact] public void SameResultsRepeatCallsStringQueryIList() { - var q = (from x in new[] { "!@#$%^", "C", "AAA", "", "Calling Twice", "SoS", string.Empty } + var q = (from x in new[] { "!@#$%^", "C", "AAA", "", "Calling Twice", "SoS", "" } where !string.IsNullOrEmpty(x) select x).ToList(); @@ -959,8 +959,9 @@ public void LazyOverflowRegression() [InlineData(10, 100, 90)] public void CountOfLazySkipTakeChain(int skip, int take, int expected) { - var totalCount = 100; - var partition1 = Enumerable.Range(1, totalCount).Skip(skip).Take(take); + const int TotalCount = 100; + + var partition1 = Enumerable.Range(1, TotalCount).Skip(skip).Take(take); Assert.Equal(expected, partition1.Count()); Assert.Equal(expected, partition1.Select(SuperEnumerable.Identity).Count()); Assert.Equal(expected, partition1.Select(SuperEnumerable.Identity).ToArray().Length); @@ -975,22 +976,22 @@ public void CountOfLazySkipTakeChain(int skip, int take, int expected) end = int.MaxValue; } - var partition2 = Enumerable.Range(1, totalCount).Take(skip..end); + var partition2 = Enumerable.Range(1, TotalCount).Take(skip..end); Assert.Equal(expected, partition2.Count()); Assert.Equal(expected, partition2.Select(SuperEnumerable.Identity).Count()); Assert.Equal(expected, partition2.Select(SuperEnumerable.Identity).ToArray().Length); - var partition3 = Enumerable.Range(1, totalCount).Take(^Math.Max(totalCount - skip, 0)..end); + var partition3 = Enumerable.Range(1, TotalCount).Take(^Math.Max(TotalCount - skip, 0)..end); Assert.Equal(expected, partition3.Count()); Assert.Equal(expected, partition3.Select(SuperEnumerable.Identity).Count()); Assert.Equal(expected, partition3.Select(SuperEnumerable.Identity).ToArray().Length); - var partition4 = Enumerable.Range(1, totalCount).Take(skip..^Math.Max(totalCount - end, 0)); + var partition4 = Enumerable.Range(1, TotalCount).Take(skip..^Math.Max(TotalCount - end, 0)); Assert.Equal(expected, partition4.Count()); Assert.Equal(expected, partition4.Select(SuperEnumerable.Identity).Count()); Assert.Equal(expected, partition4.Select(SuperEnumerable.Identity).ToArray().Length); - var partition5 = Enumerable.Range(1, totalCount).Take(^Math.Max(totalCount - skip, 0)..^Math.Max(totalCount - end, 0)); + var partition5 = Enumerable.Range(1, TotalCount).Take(^Math.Max(TotalCount - skip, 0)..^Math.Max(TotalCount - end, 0)); Assert.Equal(expected, partition5.Count()); Assert.Equal(expected, partition5.Select(SuperEnumerable.Identity).Count()); Assert.Equal(expected, partition5.Select(SuperEnumerable.Identity).ToArray().Length); @@ -1062,9 +1063,7 @@ public void ElementAtOfLazySkipTakeChain(int[] source, int skip, int take, int[] Assert.Equal(indices.Length, expectedValues.Length); for (var i = 0; i < indices.Length; i++) - { Assert.Equal(expectedValues[i], partition1.ElementAtOrDefault(indices[i])); - } int end; try @@ -1078,27 +1077,19 @@ public void ElementAtOfLazySkipTakeChain(int[] source, int skip, int take, int[] var partition2 = ForceNotCollection(source).Take(skip..end); for (var i = 0; i < indices.Length; i++) - { Assert.Equal(expectedValues[i], partition2.ElementAtOrDefault(indices[i])); - } var partition3 = ForceNotCollection(source).Take(^Math.Max(source.Length - skip, 0)..end); for (var i = 0; i < indices.Length; i++) - { Assert.Equal(expectedValues[i], partition3.ElementAtOrDefault(indices[i])); - } var partition4 = ForceNotCollection(source).Take(skip..^Math.Max(source.Length - end, 0)); for (var i = 0; i < indices.Length; i++) - { Assert.Equal(expectedValues[i], partition4.ElementAtOrDefault(indices[i])); - } var partition5 = ForceNotCollection(source).Take(^Math.Max(source.Length - skip, 0)..^Math.Max(source.Length - end, 0)); for (var i = 0; i < indices.Length; i++) - { Assert.Equal(expectedValues[i], partition5.ElementAtOrDefault(indices[i])); - } } [Fact] diff --git a/Tests/SuperLinq.Test/TestingSequence.cs b/Tests/SuperLinq.Test/TestingSequence.cs index 03cd25454..2d305cde9 100644 --- a/Tests/SuperLinq.Test/TestingSequence.cs +++ b/Tests/SuperLinq.Test/TestingSequence.cs @@ -169,12 +169,12 @@ static IEnumerable InvalidUsage(IEnumerable enumerable) { using (enumerable.GetEnumerator()) yield return 1; + using (enumerable.GetEnumerator()) yield return 2; + using (enumerable.GetEnumerator()) yield return 3; - - yield break; } static void Act() @@ -236,9 +236,8 @@ static IEnumerable InvalidUsage(IEnumerable enumerable) using var enumerator = enumerable.GetEnumerator(); while (enumerator.MoveNext()) yield return enumerator.Current; - _ = enumerator.MoveNext(); - yield break; + _ = enumerator.MoveNext(); } static void Act() @@ -258,8 +257,6 @@ static IEnumerable InvalidUsage(IEnumerable enumerable) var enumerator = enumerable.GetEnumerator(); enumerator.Dispose(); yield return enumerator.Current; - - yield break; } static void Act() @@ -279,9 +276,8 @@ static IEnumerable InvalidUsage(IEnumerable enumerable) using var enumerator = enumerable.GetEnumerator(); while (enumerator.MoveNext()) yield return enumerator.Current; - yield return enumerator.Current; - yield break; + yield return enumerator.Current; } static void Act() diff --git a/Tests/SuperLinq.Test/ToArrayByIndexTest.cs b/Tests/SuperLinq.Test/ToArrayByIndexTest.cs index 86dd9d41a..09fc8d07d 100644 --- a/Tests/SuperLinq.Test/ToArrayByIndexTest.cs +++ b/Tests/SuperLinq.Test/ToArrayByIndexTest.cs @@ -36,7 +36,7 @@ public void ToArrayByIndex(bool withLength, int[] indices) expected = expected.Replace(i, i); result.AssertSequenceEqual( - expected.Select(x => x is null ? null : new { Index = x.Value, })); + expected.Select(x => x is null ? null : new { Index = x.Value })); } [Fact] diff --git a/Tests/SuperLinq.Test/ToDataTableTest.cs b/Tests/SuperLinq.Test/ToDataTableTest.cs index 5b78f7911..4b7633fca 100644 --- a/Tests/SuperLinq.Test/ToDataTableTest.cs +++ b/Tests/SuperLinq.Test/ToDataTableTest.cs @@ -148,7 +148,7 @@ private readonly struct Point public bool IsEmpty => X == 0 && Y == 0; public int X { get; } public int Y { get; } - public Point(int x, int y) : this() { X = x; Y = y; } + public Point(int x, int y) : this() => (X, Y) = (x, y); } [Fact] @@ -159,10 +159,15 @@ public void ToDataTableIgnoresStaticMembers() Assert.Equal(3, points.Columns.Count); - DataColumn? x, y, empty; - Assert.NotNull(x = points.Columns["X"]); - Assert.NotNull(y = points.Columns["Y"]); - Assert.NotNull(empty = points.Columns["IsEmpty"]); + var (x, y, empty) = ( + points.Columns["X"], + points.Columns["Y"], + points.Columns["IsEmpty"] + ); + + Assert.NotNull(points.Columns["X"]); + Assert.NotNull(points.Columns["Y"]); + Assert.NotNull(points.Columns["IsEmpty"]); var row = points.Rows.Cast().Single(); Assert.Equal(12, row[x!]); diff --git a/Tests/SuperLinq.Test/TrySingleTest.cs b/Tests/SuperLinq.Test/TrySingleTest.cs index 7dac1499a..a25f0a155 100644 --- a/Tests/SuperLinq.Test/TrySingleTest.cs +++ b/Tests/SuperLinq.Test/TrySingleTest.cs @@ -28,7 +28,7 @@ public static IEnumerable GetSingletonSequences(IEnumerable seq) .Select(x => new object[] { x }); [Theory] - [MemberData(nameof(GetSingletonSequences), new int[] { 10, })] + [MemberData(nameof(GetSingletonSequences), new int[] { 10 })] public void TrySingleWithSingleton(IDisposableEnumerable seq) { using (seq) @@ -73,7 +73,7 @@ public IEnumerator GetEnumerator() } [Theory] - [MemberData(nameof(GetSequences), new int[] { 10, 20, })] + [MemberData(nameof(GetSequences), new int[] { 10, 20 })] public void TrySingleWithMoreThanOne(IDisposableEnumerable seq) { using (seq) diff --git a/Tests/SuperLinq.Test/UpdatablePriorityQueueTest.cs b/Tests/SuperLinq.Test/UpdatablePriorityQueueTest.cs index bf68f28df..73d33e12c 100644 --- a/Tests/SuperLinq.Test/UpdatablePriorityQueueTest.cs +++ b/Tests/SuperLinq.Test/UpdatablePriorityQueueTest.cs @@ -41,9 +41,7 @@ public abstract class UpdatablePriorityQueue_Generic_Tests const int MagicValue = 34; var seed = count * MagicValue; for (var i = 0; i < count; i++) - { yield return CreateT(seed++); - } } protected UpdatablePriorityQueue CreateEmptyUpdatablePriorityQueue(int initialCapacity = 0) @@ -126,9 +124,7 @@ public void UpdatablePriorityQueue_Enqueue_IEnumerable(int count) var queue = CreateEmptyUpdatablePriorityQueue(); foreach ((var element, var priority) in itemsToEnqueue) - { queue.Enqueue(element, priority); - } queue.UnorderedItems.AssertCollectionEqual(itemsToEnqueue); } @@ -144,9 +140,7 @@ public void UpdatablePriorityQueue_Peek_ShouldReturnMinimalElement(int count) foreach (var (element, priority) in itemsToEnqueue) { if (queue.Comparer.Compare(priority, minItem.Priority) < 0) - { minItem = (element, priority); - } queue.Enqueue(element, priority); @@ -212,9 +206,7 @@ public void UpdatablePriorityQueue_EnqueueDequeue(int count) queue.EnqueueRange(itemsToEnqueue.Take(count)); foreach ((var element, var priority) in itemsToEnqueue.Skip(count)) - { _ = queue.EnqueueDequeue(element, priority); - } var expectedItems = itemsToEnqueue.OrderByDescending(x => x.Priority, queue.Comparer).Take(count); queue.UnorderedItems.AssertCollectionEqual(expectedItems, comparer: GetNodeComparer()); @@ -317,9 +309,7 @@ private static UpdatablePriorityQueue CreateUpdatablePriorityQueue(int { var pq = new UpdatablePriorityQueue(initialCapacity); for (var i = 0; i < count; i++) - { pq.Enqueue(i, i); - } return pq; } diff --git a/Tests/SuperLinq.Test/WhereLagTest.cs b/Tests/SuperLinq.Test/WhereLagTest.cs index cae9bbd33..5bc8647f7 100644 --- a/Tests/SuperLinq.Test/WhereLagTest.cs +++ b/Tests/SuperLinq.Test/WhereLagTest.cs @@ -54,7 +54,7 @@ public void WhereLagWithNullableReferences() public void WhereLagWithNonNullableReferences() { using var seq = Seq("foo", "bar", "baz", "qux").AsTestingSequence(); - var result = seq.WhereLag(2, string.Empty, (a, b) => b == "foo" || a == "foo"); + var result = seq.WhereLag(2, "", (a, b) => b == "foo" || a == "foo"); result.AssertSequenceEqual("foo", "baz"); } } diff --git a/Tests/SuperLinq.Test/WhereLeadTest.cs b/Tests/SuperLinq.Test/WhereLeadTest.cs index 6b6763ffe..fd1854446 100644 --- a/Tests/SuperLinq.Test/WhereLeadTest.cs +++ b/Tests/SuperLinq.Test/WhereLeadTest.cs @@ -1,4 +1,4 @@ -namespace Test; +namespace Test; public sealed class WhereLeadTest { @@ -46,7 +46,7 @@ public void WhereLeadOffsetGreaterThanSequenceLength() public void WhereLeadWithNullableReferences() { using var seq = Seq("foo", "bar", "baz", "qux").AsTestingSequence(); - var result = seq.WhereLead(2, (a, b) => (b ?? a) == "baz"); + var result = seq.WhereLead(2, (a, b) => (b ?? a) is "baz"); result.AssertSequenceEqual("foo", "baz"); } @@ -54,7 +54,7 @@ public void WhereLeadWithNullableReferences() public void WhereLeadWithNonNullableReferences() { using var seq = Seq("foo", "bar", "baz", "qux").AsTestingSequence(); - var result = seq.WhereLead(2, string.Empty, (a, b) => b == "baz" || a == "baz"); + var result = seq.WhereLead(2, "", (a, b) => b is "baz" || a is "baz"); result.AssertSequenceEqual("foo", "baz"); } } diff --git a/Tests/SuperLinq.Test/WindowLeftTest.cs b/Tests/SuperLinq.Test/WindowLeftTest.cs index d63150f2b..7cb1f78eb 100644 --- a/Tests/SuperLinq.Test/WindowLeftTest.cs +++ b/Tests/SuperLinq.Test/WindowLeftTest.cs @@ -100,10 +100,11 @@ public enum WindowMethod private static IEnumerable GetWindowTestSequences(IEnumerable source) { foreach (var seq in source.GetListSequences()) - yield return new object[] { seq, WindowMethod.Traditional, }; - yield return new object[] { source.AsTestingSequence(), WindowMethod.BufferSize, }; - yield return new object[] { source.AsTestingSequence(), WindowMethod.BufferArray, }; - yield return new object[] { source.AsTestingSequence(), WindowMethod.BufferSizeArray, }; + yield return new object[] { seq, WindowMethod.Traditional }; + + yield return new object[] { source.AsTestingSequence(), WindowMethod.BufferSize }; + yield return new object[] { source.AsTestingSequence(), WindowMethod.BufferArray }; + yield return new object[] { source.AsTestingSequence(), WindowMethod.BufferSizeArray }; } private static IEnumerable> GetWindows( diff --git a/Tests/SuperLinq.Test/WindowRightTest.cs b/Tests/SuperLinq.Test/WindowRightTest.cs index e0af584cf..2d0a0eccf 100644 --- a/Tests/SuperLinq.Test/WindowRightTest.cs +++ b/Tests/SuperLinq.Test/WindowRightTest.cs @@ -102,10 +102,11 @@ public enum WindowMethod private static IEnumerable GetWindowTestSequences(IEnumerable source) { foreach (var seq in source.GetListSequences()) - yield return new object[] { seq, WindowMethod.Traditional, }; - yield return new object[] { source.AsTestingSequence(maxEnumerations: 2), WindowMethod.BufferSize, }; - yield return new object[] { source.AsTestingSequence(maxEnumerations: 2), WindowMethod.BufferArray, }; - yield return new object[] { source.AsTestingSequence(maxEnumerations: 2), WindowMethod.BufferSizeArray, }; + yield return new object[] { seq, WindowMethod.Traditional }; + + yield return new object[] { source.AsTestingSequence(maxEnumerations: 2), WindowMethod.BufferSize }; + yield return new object[] { source.AsTestingSequence(maxEnumerations: 2), WindowMethod.BufferArray }; + yield return new object[] { source.AsTestingSequence(maxEnumerations: 2), WindowMethod.BufferSizeArray }; } private static IEnumerable> GetWindows( diff --git a/Tests/SuperLinq.Test/WindowTest.cs b/Tests/SuperLinq.Test/WindowTest.cs index 78db07a01..f2469900b 100644 --- a/Tests/SuperLinq.Test/WindowTest.cs +++ b/Tests/SuperLinq.Test/WindowTest.cs @@ -103,10 +103,11 @@ public enum WindowMethod private static IEnumerable GetWindowTestSequences(IEnumerable source) { foreach (var seq in source.GetListSequences()) - yield return new object[] { seq, WindowMethod.Traditional, }; - yield return new object[] { source.AsTestingSequence(maxEnumerations: 2), WindowMethod.BufferSize, }; - yield return new object[] { source.AsTestingSequence(maxEnumerations: 2), WindowMethod.BufferArray, }; - yield return new object[] { source.AsTestingSequence(maxEnumerations: 2), WindowMethod.BufferSizeArray, }; + yield return new object[] { seq, WindowMethod.Traditional }; + + yield return new object[] { source.AsTestingSequence(maxEnumerations: 2), WindowMethod.BufferSize }; + yield return new object[] { source.AsTestingSequence(maxEnumerations: 2), WindowMethod.BufferArray }; + yield return new object[] { source.AsTestingSequence(maxEnumerations: 2), WindowMethod.BufferSizeArray }; } private static IEnumerable> GetWindows( diff --git a/Tests/SuperLinq.Test/ZipLongestTest.cs b/Tests/SuperLinq.Test/ZipLongestTest.cs index 0b18360b0..47e6d23e4 100644 --- a/Tests/SuperLinq.Test/ZipLongestTest.cs +++ b/Tests/SuperLinq.Test/ZipLongestTest.cs @@ -23,9 +23,9 @@ public static IEnumerable GetTwoParamSequences() { var parameters = new List { - new object[] { Enumerable.Range(1, 3).AsTestingSequence(), Enumerable.Range(1, 3).AsTestingSequence(), 9, }, - new object[] { Enumerable.Range(1, 3).ToList(), Enumerable.Range(1, 3).AsTestingSequence(), 9, }, - new object[] { Enumerable.Range(1, 3).AsBreakingList(), Enumerable.Range(1, 3).AsBreakingList(), 9, }, + new object[] { Enumerable.Range(1, 3).AsTestingSequence(), Enumerable.Range(1, 3).AsTestingSequence(), 9 }, + new object[] { Enumerable.Range(1, 3).ToList(), Enumerable.Range(1, 3).AsTestingSequence(), 9 }, + new object[] { Enumerable.Range(1, 3).AsBreakingList(), Enumerable.Range(1, 3).AsBreakingList(), 9 }, }; for (var i = 0; i < 2; i++) diff --git a/Tests/SuperLinq.Test/ZipMapTest.cs b/Tests/SuperLinq.Test/ZipMapTest.cs index a299385f8..52e494827 100644 --- a/Tests/SuperLinq.Test/ZipMapTest.cs +++ b/Tests/SuperLinq.Test/ZipMapTest.cs @@ -27,7 +27,7 @@ public static IEnumerable GetStringSequences1() var seq = Seq("foo", "bar", "FOO", "Bar", "baz", "QUx", "bAz", "QuX"); return seq .GetListSequences() - .Select(x => new object[] { x, seq, }); + .Select(x => new object[] { x, seq }); } [Theory] @@ -45,7 +45,7 @@ public void ZipMapStringTransformation(IDisposableEnumerable seq, IEnume public static IEnumerable GetStringSequences2() => Seq("foo", "hello", "world", "Bar", "QuX", "ay", "az") .GetListSequences() - .Select(x => new object[] { x, }); + .Select(x => new object[] { x }); [Theory] [MemberData(nameof(GetStringSequences2))] diff --git a/Tests/SuperLinq.Test/ZipShortestTest.cs b/Tests/SuperLinq.Test/ZipShortestTest.cs index 48e181e0f..f5397881f 100644 --- a/Tests/SuperLinq.Test/ZipShortestTest.cs +++ b/Tests/SuperLinq.Test/ZipShortestTest.cs @@ -51,9 +51,9 @@ public static IEnumerable GetTwoParamSequences() { var parameters = new List { - new object[] { Enumerable.Range(1, 3).AsTestingSequence(), Enumerable.Range(1, 3).AsTestingSequence(), false, }, - new object[] { Enumerable.Range(1, 3).ToList(), Enumerable.Range(1, 3).AsTestingSequence(), false, }, - new object[] { Enumerable.Range(1, 3).AsBreakingList(), Enumerable.Range(1, 3).AsBreakingList(), false, }, + new object[] { Enumerable.Range(1, 3).AsTestingSequence(), Enumerable.Range(1, 3).AsTestingSequence(), false }, + new object[] { Enumerable.Range(1, 3).ToList(), Enumerable.Range(1, 3).AsTestingSequence(), false }, + new object[] { Enumerable.Range(1, 3).AsBreakingList(), Enumerable.Range(1, 3).AsBreakingList(), false }, }; for (var i = 0; i < 2; i++) From d706f402dda2346b4050863d9fb44c7eadfb9179 Mon Sep 17 00:00:00 2001 From: Stuart Turner Date: Fri, 12 Apr 2024 10:30:14 -0500 Subject: [PATCH 2/4] ... --- Source/SuperLinq/Subsets.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SuperLinq/Subsets.cs b/Source/SuperLinq/Subsets.cs index a3f16a9fd..7e71f3479 100644 --- a/Source/SuperLinq/Subsets.cs +++ b/Source/SuperLinq/Subsets.cs @@ -146,8 +146,8 @@ private static IEnumerable> Subsets(List set, int subsetSize) subset[i] = set[indices[i] - 1]; yield return subset; - } + while (indices[0] != setSize - subsetSize + 1); } } From ddc9cf0aa8d1e5553e5711d5b1584a29350d3f9b Mon Sep 17 00:00:00 2001 From: Stuart Turner Date: Fri, 12 Apr 2024 10:31:18 -0500 Subject: [PATCH 3/4] ... --- Source/SuperLinq/Subsets.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/SuperLinq/Subsets.cs b/Source/SuperLinq/Subsets.cs index 7e71f3479..d283c986a 100644 --- a/Source/SuperLinq/Subsets.cs +++ b/Source/SuperLinq/Subsets.cs @@ -147,7 +147,6 @@ private static IEnumerable> Subsets(List set, int subsetSize) yield return subset; } - while (indices[0] != setSize - subsetSize + 1); } } From 9fa0ee51837db7ca32683e69525fa02dfca559a4 Mon Sep 17 00:00:00 2001 From: Stuart Turner Date: Fri, 12 Apr 2024 10:33:26 -0500 Subject: [PATCH 4/4] ... --- Source/SuperLinq/CountBy.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SuperLinq/CountBy.cs b/Source/SuperLinq/CountBy.cs index ade3a7814..4d8bd99f7 100644 --- a/Source/SuperLinq/CountBy.cs +++ b/Source/SuperLinq/CountBy.cs @@ -33,7 +33,7 @@ public static partial class SuperEnumerable #if NET9_0_OR_GREATER [Obsolete("This method has been implemented by the framework.")] public static IEnumerable> CountBy( - IEnumerable source, + IEnumerable source, Func keySelector ) #else