8000 Replace explicit type mentions with object pattern by atifaziz · Pull Request #751 · morelinq/MoreLINQ · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Replace explicit type mentions with object pattern #751

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

Merged
merged 1 commit into from
Aug 6, 2020
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
8000
8 changes: 4 additions & 4 deletions MoreLinq.Test/AggregateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ public void SevenUniqueAccumulators()
0, (s, e) => s + e.Num,
0, (s, e) => e.Num % 2 == 0 ? s + e.Num : s,
0, (s, _) => s + 1,
(int?)null, (s, e) => s is int n ? Math.Min(n, e.Num) : e.Num,
(int?)null, (s, e) => s is int n ? Math.Max(n, e.Num) : e.Num,
(int?)null, (s, e) => s is {} n ? Math.Min(n, e.Num) : e.Num,
(int?)null, (s, e) => s is {} n ? Math.Max(n, e.Num) : e.Num,
new HashSet<int>(), (s, e) => { s.Add(e.Str.Length); return s; },
new List<(int Num, string Str)>(), (s, e) => { s.Add((e.Num, e.Str)); return s; },
(sum, esum, count, min, max, lengths, items) => new
Expand All @@ -120,8 +120,8 @@ public void SevenUniqueAccumulators()
EvenSum = esum,
Count = count,
Average = (double)sum / count,
Min = min is int mn ? mn : throw new InvalidOperationException(),
Max = max is int mx ? mx : throw new InvalidOperationException(),
Min = min is {} mn ? mn : throw new InvalidOperationException(),
Max = max is {} mx ? mx : throw new InvalidOperationException(),
UniqueLengths = lengths,
Items = items,
}
Expand Down
2 changes: 1 addition & 1 deletion MoreLinq.Test/ChooseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static class Option<T>
public void ThoseThatAreIntegers()
{
new int?[] { 0, 1, 2, null, 4, null, 6, null, null, 9 }
.Choose(e => e is int n ? Option.Some(n) : Option<int>.None)
.Choose(e => e is {} n ? Option.Some(n) : Option<int>.None)
.AssertSequenceEqual(0, 1, 2, 4, 6, 9);
}

Expand Down
2 changes: 1 addition & 1 deletion MoreLinq/AssertCount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static IEnumerable<TSource> AssertCountImpl<TSource>(IEnumerable<TSource> source
if (errorSelector == null) throw new ArgumentNullException(nameof(errorSelector));

return
source.TryGetCollectionCount() is int collectionCount
source.TryGetCollectionCount() is {} collectionCount
? collectionCount == count
? source
: From<TSource>(() => throw errorSelector(collectionCount.CompareTo(count), count))
Expand Down
2 changes: 1 addition & 1 deletion MoreLinq/Backsert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static IEnumerable<T> Backsert<T>(this IEnumerable<T> first, IEnumerable<
if (e.MoveNext())
{
var (_, countdown) = e.Current;
if (countdown is int n && n != index - 1)
if (countdown is {} n && n != index - 1)
throw new ArgumentOutOfRangeException(nameof(index), "Insertion index is greater than the length of the first sequence.");

do
Expand Down
4 changes: 2 additions & 2 deletions MoreLinq/CountDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public static IEnumerable<TResult> CountDown<T, TResult>(this IEnumerable<T> sou
if (source == null) throw new ArgumentNullException(nameof(source));
if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector));

return source.TryAsListLike() is IListLike<T> listLike
return source.TryAsListLike() is {} listLike
? IterateList(listLike)
: source.TryGetCollectionCount() is int collectionCount
: source.TryGetCollectionCount() is {} collectionCount
? IterateCollection(collectionCount)
: IterateSequence();

Expand Down
4 changes: 2 additions & 2 deletions MoreLinq/CountMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ public static int CompareCount<TFirst, TSecond>(this IEnumerable<TFirst> first,
if (first == null) throw new ArgumentNullException(nameof(first));
if (second == null) throw new ArgumentNullException(nameof(second));

if (first.TryGetCollectionCount() is int firstCount)
if (first.TryGetCollectionCount() is {} firstCount)
{
return firstCount.CompareTo(second.TryGetCollectionCount() ?? second.CountUpTo(firstCount + 1));
}
else if (second.TryGetCollectionCount() is int secondCount)
else if (second.TryGetCollectionCount() is {} secondCount)
{
return first.CountUpTo(secondCount + 1).CompareTo(secondCount);
}
Expand Down
4 changes: 2 additions & 2 deletions MoreLinq/EndsWith.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public static bool EndsWith<T>(this IEnumerable<T> first, IEnumerable<T> second,
comparer ??= EqualityComparer<T>.Default;

List<T> secondList;
return second.TryGetCollectionCount() is int secondCount
? first.TryGetCollectionCount() is int firstCount && secondCount > firstCount
return second.TryGetCollectionCount() is {} secondCount
? first.TryGetCollectionCount() is {} firstCount && secondCount > firstCount
? false
: Impl(second, secondCount)
: Impl(secondList = second.ToList(), secondList.Count);
Expand Down
2 changes: 1 addition & 1 deletion MoreLinq/Experimental/Await.cs
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ void OnPendingCompleted()
onEnd();
}

var concurrencyGate = maxConcurrency is int count
var concurrencyGate = maxConcurrency is {} count
? new ConcurrencyGate(count)
: ConcurrencyGate.Unbounded;

Expand Down
2 changes: 1 addition & 1 deletion MoreLinq/Experimental/TrySingle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static TResult TrySingle<T, TCardinality, TResult>(this IEnumerable<T> so
};
return resultSelector(one, item);
}
case int _:
case {}:
return resultSelector(many, default);
default:
{
Expand Down
2 changes: 1 addition & 1 deletion MoreLinq/FallbackIfEmpty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ static IEnumerable<T> FallbackIfEmptyImpl<T>(IEnumerable<T> source,
int? count, T fallback1, T fallback2, T fallback3, T fallback4,
IEnumerable<T> fallback)
{
return source.TryGetCollectionCount() is int collectionCount
return source.TryGetCollectionCount() is {} collectionCount
? collectionCount == 0 ? Fallback() : source
: _();

Expand Down
2 changes: 1 addition & 1 deletion MoreLinq/Flatten.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static IEnumerable<object> Flatten(this IEnumerable source, Func<object,

while (e.MoveNext())
{
if (selector(e.Current) is IEnumerable inner)
if (selector(e.Current) is {} inner)
{
stack.Push(e);
e = inner.GetEnumerator();
Expand Down
2 changes: 1 addition & 1 deletion MoreLinq/PadStart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ static IEnumerable<T> PadStartImpl<T>(IEnumerable<T> source,
int width, T padding, Func<int, T> paddingSelector)
{
return
source.TryGetCollectionCount() is int collectionCount
source.TryGetCollectionCount() is {} collectionCount
? collectionCount >= width
? source
: Enumerable.Range(0, width - collectionCount)
Expand Down
2 changes: 1 addition & 1 deletion MoreLinq/SkipLast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static IEnumerable<T> SkipLast<T>(this IEnumerable<T> source, int count)
return source;

return
source.TryGetCollectionCount() is int collectionCount
source.TryGetCollectionCount() is {} collectionCount
? source.Take(collectionCount - count)
: source.CountDown(count, (e, cd) => (Element: e, Countdown: cd ))
.TakeWhile(e => e.Countdown == null)
Expand Down
4 changes: 2 additions & 2 deletions MoreLinq/StartsWith.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public static bool StartsWith<T>(this IEnumerable<T> first, IEnumerable<T> secon
if (first == null) throw new ArgumentNullException(nameof(first));
if (second == null) throw new ArgumentNullException(nameof(second));

if (first.TryGetCollectionCount() is int firstCount &&
second.TryGetCollectionCount() is int secondCount &&
if (first.TryGetCollectionCount() is {} firstCount &&
second.TryGetCollectionCount() is {} secondCount &&
secondCount > firstCount)
{
return false;
Expand Down
2 changes: 1 addition & 1 deletion MoreLinq/TakeLast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static IEnumerable<TSource> TakeLast<TSource>(this IEnumerable<TSource> s
return Enumerable.Empty<TSource>();

return
source.TryGetCollectionCount() is int collectionCount
source.TryGetCollectionCount() is {} collectionCount
? source.Slice(Math.Max(0, collectionCount - count), int.MaxValue)
: source.CountDown(count, (e, cd) => (Element: e, Countdown: cd))
.SkipWhile(e => e.Countdown == null)
Expand Down
0