Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style consistency improvements #650

Merged
merged 4 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ 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
dotnet_naming_rule.instance_fields_should_be_camel_case.symbols = instance_fields
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
5 changes: 3 additions & 2 deletions Generators/SuperLinq.Generator/ToDelimitedString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
71 changes: 59 additions & 12 deletions Source/SuperLinq.Async/AggregateRight.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SuperLinq.Async;
namespace SuperLinq.Async;

public static partial class AsyncSuperEnumerable
{
Expand All @@ -23,7 +23,11 @@ public static partial class AsyncSuperEnumerable
/// <remarks>
/// This operator executes immediately.
/// </remarks>
public static ValueTask<TSource> AggregateRight<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, TSource, TSource> func, CancellationToken cancellationToken = default)
public static ValueTask<TSource> AggregateRight<TSource>(
this IAsyncEnumerable<TSource> source,
Func<TSource, TSource, TSource> func,
CancellationToken cancellationToken = default
)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(func);
Expand Down Expand Up @@ -52,7 +56,11 @@ public static ValueTask<TSource> AggregateRight<TSource>(this IAsyncEnumerable<T
/// <remarks>
/// This operator executes immediately.
/// </remarks>
public static ValueTask<TSource> AggregateRight<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, TSource, ValueTask<TSource>> func, CancellationToken cancellationToken = default)
public static ValueTask<TSource> AggregateRight<TSource>(
this IAsyncEnumerable<TSource> source,
Func<TSource, TSource, ValueTask<TSource>> func,
CancellationToken cancellationToken = default
)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(func);
Expand Down Expand Up @@ -84,7 +92,8 @@ public static ValueTask<TSource> AggregateRight<TSource>(this IAsyncEnumerable<T
public static ValueTask<TSource> AggregateRight<TSource>(
this IAsyncEnumerable<TSource> source,
Func<TSource, TSource, CancellationToken, ValueTask<TSource>> func,
CancellationToken cancellationToken = default)
CancellationToken cancellationToken = default
)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(func);
Expand Down Expand Up @@ -136,7 +145,12 @@ static async ValueTask<TSource> Core(
/// This operator executes immediately.
/// </remarks>

public static ValueTask<TAccumulate> AggregateRight<TSource, TAccumulate>(this IAsyncEnumerable<TSource> source, TAccumulate seed, Func<TSource, TAccumulate, TAccumulate> func, CancellationToken cancellationToken = default)
public static ValueTask<TAccumulate> AggregateRight<TSource, TAccumulate>(
this IAsyncEnumerable<TSource> source,
TAccumulate seed,
Func<TSource, TAccumulate, TAccumulate> func,
CancellationToken cancellationToken = default
)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(func);
Expand Down Expand Up @@ -170,7 +184,12 @@ public static ValueTask<TAccumulate> AggregateRight<TSource, TAccumulate>(this I
/// This operator executes immediately.
/// </remarks>

public static ValueTask<TAccumulate> AggregateRight<TSource, TAccumulate>(this IAsyncEnumerable<TSource> source, TAccumulate seed, Func<TSource, TAccumulate, ValueTask<TAccumulate>> func, CancellationToken cancellationToken = default)
public static ValueTask<TAccumulate> AggregateRight<TSource, TAccumulate>(
this IAsyncEnumerable<TSource> source,
TAccumulate seed,
Func<TSource, TAccumulate, ValueTask<TAccumulate>> func,
CancellationToken cancellationToken = default
)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(func);
Expand Down Expand Up @@ -204,7 +223,12 @@ public static ValueTask<TAccumulate> AggregateRight<TSource, TAccumulate>(this I
/// This operator executes immediately.
/// </remarks>

public static ValueTask<TAccumulate> AggregateRight<TSource, TAccumulate>(this IAsyncEnumerable<TSource> source, TAccumulate seed, Func<TSource, TAccumulate, CancellationToken, ValueTask<TAccumulate>> func, CancellationToken cancellationToken = default)
public static ValueTask<TAccumulate> AggregateRight<TSource, TAccumulate>(
this IAsyncEnumerable<TSource> source,
TAccumulate seed,
Func<TSource, TAccumulate, CancellationToken, ValueTask<TAccumulate>> func,
CancellationToken cancellationToken = default
)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(func);
Expand Down Expand Up @@ -254,12 +278,22 @@ static async ValueTask<TAccumulate> Core(
/// This operator executes immediately.
/// </remarks>

public static ValueTask<TResult> AggregateRight<TSource, TAccumulate, TResult>(this IAsyncEnumerable<TSource> source, TAccumulate seed, Func<TSource, TAccumulate, TAccumulate> func, Func<TAccumulate, TResult> resultSelector, CancellationToken cancellationToken = default)
public static ValueTask<TResult> AggregateRight<TSource, TAccumulate, TResult>(
this IAsyncEnumerable<TSource> source,
TAccumulate seed,
Func<TSource, TAccumulate, TAccumulate> func,
Func<TAccumulate, TResult> resultSelector,
CancellationToken cancellationToken = default
)
{
ArgumentNullException.ThrowIfNull(func);
ArgumentNullException.ThrowIfNull(resultSelector);

return source.AggregateRight(seed, (a, b, ct) => new ValueTask<TAccumulate>(func(a, b)), (a, ct) => new ValueTask<TResult>(resultSelector(a)), cancellationToken);
return source.AggregateRight(
seed,
(a, b, ct) => new ValueTask<TAccumulate>(func(a, b)),
(a, ct) => new ValueTask<TResult>(resultSelector(a)),
cancellationToken);
}

/// <summary>
Expand Down Expand Up @@ -292,7 +326,13 @@ public static ValueTask<TResult> AggregateRight<TSource, TAccumulate, TResult>(t
/// This operator executes immediately.
/// </remarks>

public static ValueTask<TResult> AggregateRight<TSource, TAccumulate, TResult>(this IAsyncEnumerable<TSource> source, TAccumulate seed, Func<TSource, TAccumulate, ValueTask<TAccumulate>> func, Func<TAccumulate, ValueTask<TResult>> resultSelector, CancellationToken cancellationToken = default)
public static ValueTask<TResult> AggregateRight<TSource, TAccumulate, TResult>(
this IAsyncEnumerable<TSource> source,
TAccumulate seed,
Func<TSource, TAccumulate, ValueTask<TAccumulate>> func,
Func<TAccumulate, ValueTask<TResult>> resultSelector,
CancellationToken cancellationToken = default
)
{
ArgumentNullException.ThrowIfNull(func);
ArgumentNullException.ThrowIfNull(resultSelector);
Expand Down Expand Up @@ -330,7 +370,13 @@ public static ValueTask<TResult> AggregateRight<TSource, TAccumulate, TResult>(t
/// This operator executes immediately.
/// </remarks>

public static ValueTask<TResult> AggregateRight<TSource, TAccumulate, TResult>(this IAsyncEnumerable<TSource> source, TAccumulate seed, Func<TSource, TAccumulate, CancellationToken, ValueTask<TAccumulate>> func, Func<TAccumulate, CancellationToken, ValueTask<TResult>> resultSelector, CancellationToken cancellationToken = default)
public static ValueTask<TResult> AggregateRight<TSource, TAccumulate, TResult>(
this IAsyncEnumerable<TSource> source,
TAccumulate seed,
Func<TSource, TAccumulate, CancellationToken, ValueTask<TAccumulate>> func,
Func<TAccumulate, CancellationToken, ValueTask<TResult>> resultSelector,
CancellationToken cancellationToken = default
)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(func);
Expand All @@ -344,6 +390,7 @@ static async ValueTask<TResult> Core(
Func<TSource, TAccumulate, CancellationToken, ValueTask<TAccumulate>> func,
Func<TAccumulate, CancellationToken, ValueTask<TResult>> 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);
}
}
1 change: 1 addition & 0 deletions Source/SuperLinq.Async/AssertCount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ static async IAsyncEnumerable<TSource> Core(
{
if (++c > count)
break;

yield return item;
}

Expand Down
8 changes: 5 additions & 3 deletions Source/SuperLinq.Async/AsyncSuperEnumerable.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
namespace SuperLinq.Async;
namespace SuperLinq.Async;

/// <summary>
/// Provides a set of static methods for querying objects that
/// implement <see cref="IAsyncEnumerable{T}" />.
/// </summary>
public static partial class AsyncSuperEnumerable
{
internal static ConfiguredCancelableAsyncEnumerable<T>.Enumerator GetConfiguredAsyncEnumerator<T>(this IAsyncEnumerable<T> enumerable, CancellationToken cancellationToken) =>
enumerable.ConfigureAwait(false).WithCancellation(cancellationToken).GetAsyncEnumerator();
internal static ConfiguredCancelableAsyncEnumerable<T>.Enumerator GetConfiguredAsyncEnumerator<T>(
this IAsyncEnumerable<T> enumerable,
CancellationToken cancellationToken
) => enumerable.ConfigureAwait(false).WithCancellation(cancellationToken).GetAsyncEnumerator();

private static (bool HasValue, T Value) Some<T>(T value) => (true, value);

Expand Down
40 changes: 33 additions & 7 deletions Source/SuperLinq.Async/BindByIndex.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SuperLinq.Async;
namespace SuperLinq.Async;

public static partial class AsyncSuperEnumerable
{
Expand All @@ -16,9 +16,18 @@ public static partial class AsyncSuperEnumerable
/// <exception cref="ArgumentOutOfRangeException">An index in <paramref name="indices"/> is out of range for the input sequence <paramref name="source"/>.</exception>
public static IAsyncEnumerable<TSource> BindByIndex<TSource>(
this IAsyncEnumerable<TSource> source,
IAsyncEnumerable<int> indices)
IAsyncEnumerable<int> indices
)
{
return BindByIndex(source, indices, static (e, i) => e, static i => ThrowHelper.ThrowArgumentOutOfRangeException<TSource>(nameof(indices), "Index is greater than the length of the first sequence."));
return BindByIndex(
source,
indices,
static (e, i) => e,
static i => ThrowHelper.ThrowArgumentOutOfRangeException<TSource>(
nameof(indices),
"Index is greater than the length of the first sequence."
)
);
}

/// <summary>
Expand Down Expand Up @@ -47,7 +56,8 @@ public static IAsyncEnumerable<TResult> BindByIndex<TSource, TResult>(
this IAsyncEnumerable<TSource> source,
IAsyncEnumerable<int> indices,
Func<TSource, int, TResult> resultSelector,
Func<int, TResult> missingSelector)
Func<int, TResult> missingSelector
)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(indices);
Expand All @@ -57,11 +67,27 @@ public static IAsyncEnumerable<TResult> BindByIndex<TSource, TResult>(
return Core(source, indices, resultSelector, missingSelector);

static async IAsyncEnumerable<TResult> Core(
IAsyncEnumerable<TSource> source, IAsyncEnumerable<int> indices, Func<TSource, int, TResult> resultSelector, Func<int, TResult> missingSelector,
[EnumeratorCancellation] CancellationToken cancellationToken = default)
IAsyncEnumerable<TSource> source,
IAsyncEnumerable<int> indices,
Func<TSource, int, TResult> resultSelector,
Func<int, TResult> 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<int, TSource>();

Expand Down
2 changes: 1 addition & 1 deletion Source/SuperLinq.Async/Catch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static IAsyncEnumerable<TSource> Catch<TSource>(this IAsyncEnumerable<TSo
ArgumentNullException.ThrowIfNull(first);
ArgumentNullException.ThrowIfNull(second);

return Catch(new[] { first, second, });
return Catch(new[] { first, second });
}

/// <summary>
Expand Down
17 changes: 12 additions & 5 deletions Source/SuperLinq.Async/Choose.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SuperLinq.Async;
namespace SuperLinq.Async;

public static partial class AsyncSuperEnumerable
{
Expand Down Expand Up @@ -31,7 +31,8 @@ public static partial class AsyncSuperEnumerable

public static IAsyncEnumerable<TResult> Choose<T, TResult>(
this IAsyncEnumerable<T> source,
Func<T, (bool, TResult)> chooser)
Func<T, (bool, TResult)> chooser
)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(chooser);
Expand Down Expand Up @@ -68,7 +69,8 @@ public static IAsyncEnumerable<TResult> Choose<T, TResult>(

public static IAsyncEnumerable<TResult> Choose<T, TResult>(
this IAsyncEnumerable<T> source,
Func<T, ValueTask<(bool, TResult)>> chooser)
Func<T, ValueTask<(bool, TResult)>> chooser
)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(chooser);
Expand Down Expand Up @@ -105,14 +107,19 @@ public static IAsyncEnumerable<TResult> Choose<T, TResult>(

public static IAsyncEnumerable<TResult> Choose<T, TResult>(
this IAsyncEnumerable<T> source,
Func<T, CancellationToken, ValueTask<(bool, TResult)>> chooser)
Func<T, CancellationToken, ValueTask<(bool, TResult)>> chooser
)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(chooser);

return Core(source, chooser);

static async IAsyncEnumerable<TResult> Core(IAsyncEnumerable<T> source, Func<T, CancellationToken, ValueTask<(bool, TResult)>> chooser, [EnumeratorCancellation] CancellationToken cancellationToken = default)
static async IAsyncEnumerable<TResult> Core(
IAsyncEnumerable<T> source,
Func<T, CancellationToken, ValueTask<(bool, TResult)>> chooser,
[EnumeratorCancellation] CancellationToken cancellationToken = default
)
{
await foreach (var item in source.WithCancellation(cancellationToken).ConfigureAwait(false))
{
Expand Down
4 changes: 2 additions & 2 deletions Source/SuperLinq.Async/CollectionEqual.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static partial class AsyncSuperEnumerable
/// <remarks>
/// <para>
/// This method uses the default equality comparer for <typeparamref name="TSource"/>, <see cref="EqualityComparer{T}.Default"/>, to
/// build a <see cref="HashSet{T}" /> of the items from <paramref name="first"/>; and
/// build a <see cref="HashSet{T}" /> of the items from <paramref name="first"/>; and
/// compares the collection to <paramref name="second"/> using <see cref="HashSet{T}.SetEquals(IEnumerable{T})"/>.
/// </para>
/// <para>
Expand Down Expand Up @@ -66,7 +66,7 @@ public static ValueTask<bool> CollectionEqual<TSource>(
/// <remarks>
/// <para>
/// This method uses the provided equality comparer for <typeparamref name="TSource"/> to
/// build a <see cref="HashSet{T}" /> of the items from <paramref name="first"/>; and
/// build a <see cref="HashSet{T}" /> of the items from <paramref name="first"/>; and
/// compares the collection to <paramref name="second"/> using <see cref="HashSet{T}.SetEquals(IEnumerable{T})"/>.
/// If <paramref name="comparer"/> is <see langword="null"/>, the default equality comparer,
/// <see cref="EqualityComparer{T}.Default"/>, is used.
Expand Down
8 changes: 5 additions & 3 deletions Source/SuperLinq.Async/ConcurrentMerge.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SuperLinq.Async;
namespace SuperLinq.Async;

public static partial class AsyncSuperEnumerable
{
Expand Down Expand Up @@ -105,8 +105,10 @@ void DisposeAsync(IAsyncEnumerator<TSource> 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();
Expand Down
Loading