Skip to content

Commit

Permalink
Use null-coalescing assignment.
Browse files Browse the repository at this point in the history
  • Loading branch information
bartdesmet committed May 21, 2019
1 parent fdc613c commit c23993c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@ public static IAsyncEnumerable<TSource> DistinctUntilChanged<TSource, TKey>(this
private static IAsyncEnumerable<TSource> DistinctUntilChangedCore<TSource>(IAsyncEnumerable<TSource> source, IEqualityComparer<TSource> comparer)
{
#if USE_ASYNC_ITERATOR
if (comparer == null)
{
comparer = EqualityComparer<TSource>.Default;
}
comparer ??= EqualityComparer<TSource>.Default;

return AsyncEnumerable.Create(Core);

Expand Down Expand Up @@ -135,10 +132,7 @@ async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
private static IAsyncEnumerable<TSource> DistinctUntilChangedCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
{
#if USE_ASYNC_ITERATOR
if (comparer == null)
{
comparer = EqualityComparer<TKey>.Default;
}
comparer ??= EqualityComparer<TKey>.Default;

return AsyncEnumerable.Create(Core);

Expand Down Expand Up @@ -180,10 +174,7 @@ async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
private static IAsyncEnumerable<TSource> DistinctUntilChangedCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer)
{
#if USE_ASYNC_ITERATOR
if (comparer == null)
{
comparer = EqualityComparer<TKey>.Default;
}
comparer ??= EqualityComparer<TKey>.Default;

return AsyncEnumerable.Create(Core);

Expand Down Expand Up @@ -226,10 +217,7 @@ async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
private static IAsyncEnumerable<TSource> DistinctUntilChangedCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer)
{
#if USE_ASYNC_ITERATOR
if (comparer == null)
{
comparer = EqualityComparer<TKey>.Default;
}
comparer ??= EqualityComparer<TKey>.Default;

return AsyncEnumerable.Create(Core);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ public static ValueTask<TSource> MaxAsync<TSource>(this IAsyncEnumerable<TSource

static async ValueTask<TSource> Core(IAsyncEnumerable<TSource> source, IComparer<TSource> comparer, CancellationToken cancellationToken)
{
if (comparer == null)
{
comparer = Comparer<TSource>.Default;
}
comparer ??= Comparer<TSource>.Default;

await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,31 +76,22 @@ public static ValueTask<IList<TSource>> MaxByAsync<TSource, TKey>(this IAsyncEnu

private static ValueTask<IList<TSource>> MaxByCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey> comparer, CancellationToken cancellationToken)
{
if (comparer == null)
{
comparer = Comparer<TKey>.Default;
}
comparer ??= Comparer<TKey>.Default;

return ExtremaBy(source, keySelector, (key, minValue) => comparer.Compare(key, minValue), cancellationToken);
}

private static ValueTask<IList<TSource>> MaxByCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IComparer<TKey> comparer, CancellationToken cancellationToken)
{
if (comparer == null)
{
comparer = Comparer<TKey>.Default;
}
comparer ??= Comparer<TKey>.Default;

return ExtremaBy(source, keySelector, (key, minValue) => comparer.Compare(key, minValue), cancellationToken);
}

#if !NO_DEEP_CANCELLATION
private static ValueTask<IList<TSource>> MaxByCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IComparer<TKey> comparer, CancellationToken cancellationToken)
{
if (comparer == null)
{
comparer = Comparer<TKey>.Default;
}
comparer ??= Comparer<TKey>.Default;

return ExtremaBy(source, keySelector, (key, minValue) => comparer.Compare(key, minValue), cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ public static ValueTask<TSource> MinAsync<TSource>(this IAsyncEnumerable<TSource

static async ValueTask<TSource> Core(IAsyncEnumerable<TSource> source, IComparer<TSource> comparer, CancellationToken cancellationToken)
{
if (comparer == null)
{
comparer = Comparer<TSource>.Default;
}
comparer ??= Comparer<TSource>.Default;

await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,31 +76,22 @@ public static ValueTask<IList<TSource>> MinByAsync<TSource, TKey>(this IAsyncEnu

private static ValueTask<IList<TSource>> MinByCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey> comparer, CancellationToken cancellationToken)
{
if (comparer == null)
{
comparer = Comparer<TKey>.Default;
}
comparer ??= Comparer<TKey>.Default;

return ExtremaBy(source, keySelector, (key, minValue) => -comparer.Compare(key, minValue), cancellationToken);
}

private static ValueTask<IList<TSource>> MinByCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IComparer<TKey> comparer, CancellationToken cancellationToken)
{
if (comparer == null)
{
comparer = Comparer<TKey>.Default;
}
comparer ??= Comparer<TKey>.Default;

return ExtremaBy(source, keySelector, (key, minValue) => -comparer.Compare(key, minValue), cancellationToken);
}

#if !NO_DEEP_CANCELLATION
private static ValueTask<IList<TSource>> MinByCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IComparer<TKey> comparer, CancellationToken cancellationToken)
{
if (comparer == null)
{
comparer = Comparer<TKey>.Default;
}
comparer ??= Comparer<TKey>.Default;

return ExtremaBy(source, keySelector, (key, minValue) => -comparer.Compare(key, minValue), cancellationToken);
}
Expand Down

0 comments on commit c23993c

Please sign in to comment.