All, ANy, Contains, SequeuceEqual

master
neuecc 2020-05-10 00:07:51 +09:00
parent e93bcbf564
commit 31b788a2c9
8 changed files with 495 additions and 3154 deletions

View File

@ -1,775 +1,108 @@
namespace Cysharp.Threading.Tasks.Linq using Cysharp.Threading.Tasks.Internal;
using System;
using System.Threading;
namespace Cysharp.Threading.Tasks.Linq
{ {
internal sealed class All public static partial class UniTaskAsyncEnumerable
{ {
public static UniTask<Boolean> AllAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken = default)
{
Error.ThrowArgumentNullException(source, nameof(source));
Error.ThrowArgumentNullException(predicate, nameof(predicate));
return All.InvokeAsync(source, predicate, cancellationToken);
} }
public static UniTask<Boolean> AllAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
{
Error.ThrowArgumentNullException(source, nameof(source));
Error.ThrowArgumentNullException(predicate, nameof(predicate));
return All.InvokeAsync(source, predicate, cancellationToken);
} }
public static UniTask<Boolean> AllAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
{
Error.ThrowArgumentNullException(source, nameof(source));
Error.ThrowArgumentNullException(predicate, nameof(predicate));
return All.InvokeAsync(source, predicate, cancellationToken);
}
}
internal static class All
{
internal static async UniTask<bool> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken)
{
var e = source.GetAsyncEnumerator(cancellationToken);
try
{
while (await e.MoveNextAsync())
{
if (!predicate(e.Current))
{
return false;
}
}
return true;
}
finally
{
if (e != null)
{
await e.DisposeAsync();
}
}
}
internal static async UniTask<bool> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken)
{
var e = source.GetAsyncEnumerator(cancellationToken);
try
{
while (await e.MoveNextAsync())
{
if (!await predicate(e.Current))
{
return false;
}
}
return true;
}
finally
{
if (e != null)
{
await e.DisposeAsync();
}
}
}
internal static async UniTask<bool> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken)
{
var e = source.GetAsyncEnumerator(cancellationToken);
try
{
while (await e.MoveNextAsync())
{
if (!await predicate(e.Current, cancellationToken))
{
return false;
}
}
return true;
}
finally
{
if (e != null)
{
await e.DisposeAsync();
}
}
}
}
}

View File

@ -1,775 +1,136 @@
namespace Cysharp.Threading.Tasks.Linq using Cysharp.Threading.Tasks.Internal;
using System;
using System.Threading;
namespace Cysharp.Threading.Tasks.Linq
{ {
internal sealed class Any public static partial class UniTaskAsyncEnumerable
{ {
public static UniTask<Boolean> AnyAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken = default)
{
Error.ThrowArgumentNullException(source, nameof(source));
return Any.InvokeAsync(source, cancellationToken);
} }
public static UniTask<Boolean> AnyAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken = default)
{
Error.ThrowArgumentNullException(source, nameof(source));
Error.ThrowArgumentNullException(predicate, nameof(predicate));
return Any.InvokeAsync(source, predicate, cancellationToken);
} }
public static UniTask<Boolean> AnyAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
{
Error.ThrowArgumentNullException(source, nameof(source));
Error.ThrowArgumentNullException(predicate, nameof(predicate));
return Any.InvokeAsync(source, predicate, cancellationToken);
}
public static UniTask<Boolean> AnyAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
{
Error.ThrowArgumentNullException(source, nameof(source));
Error.ThrowArgumentNullException(predicate, nameof(predicate));
return Any.InvokeAsync(source, predicate, cancellationToken);
}
}
internal static class Any
{
internal static async UniTask<bool> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
{
var e = source.GetAsyncEnumerator(cancellationToken);
try
{
if (await e.MoveNextAsync())
{
return true;
}
return false;
}
finally
{
if (e != null)
{
await e.DisposeAsync();
}
}
}
internal static async UniTask<bool> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken)
{
var e = source.GetAsyncEnumerator(cancellationToken);
try
{
while (await e.MoveNextAsync())
{
if (predicate(e.Current))
{
return true;
}
}
return false;
}
finally
{
if (e != null)
{
await e.DisposeAsync();
}
}
}
internal static async UniTask<bool> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken)
{
var e = source.GetAsyncEnumerator(cancellationToken);
try
{
while (await e.MoveNextAsync())
{
if (await predicate(e.Current))
{
return true;
}
}
return false;
}
finally
{
if (e != null)
{
await e.DisposeAsync();
}
}
}
internal static async UniTask<bool> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken)
{
var e = source.GetAsyncEnumerator(cancellationToken);
try
{
while (await e.MoveNextAsync())
{
if (await predicate(e.Current, cancellationToken))
{
return true;
}
}
return false;
}
finally
{
if (e != null)
{
await e.DisposeAsync();
}
}
}
}
}

View File

@ -1,775 +1,50 @@
namespace Cysharp.Threading.Tasks.Linq using Cysharp.Threading.Tasks.Internal;
using System;
using System.Collections.Generic;
using System.Threading;
namespace Cysharp.Threading.Tasks.Linq
{ {
internal sealed class Contains public static partial class UniTaskAsyncEnumerable
{ {
public static UniTask<Boolean> ContainsAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, TSource value, CancellationToken cancellationToken = default)
{
return ContainsAsync(source, value, EqualityComparer<TSource>.Default, cancellationToken);
} }
public static UniTask<Boolean> ContainsAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, TSource value, IEqualityComparer<TSource> comparer, CancellationToken cancellationToken = default)
{
Error.ThrowArgumentNullException(source, nameof(source));
Error.ThrowArgumentNullException(comparer, nameof(comparer));
return Contains.InvokeAsync(source, value, comparer, cancellationToken);
}
} }
internal static class Contains
{
internal static async UniTask<bool> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, TSource value, IEqualityComparer<TSource> comparer, CancellationToken cancellationToken)
{
var e = source.GetAsyncEnumerator(cancellationToken);
try
{
while (await e.MoveNextAsync())
{
if (comparer.Equals(value, e.Current))
{
return true;
}
}
return false;
}
finally
{
if (e != null)
{
await e.DisposeAsync();
}
}
}
}
}

View File

@ -10,7 +10,7 @@ namespace Cysharp.Threading.Tasks.Linq
{ {
Error.ThrowArgumentNullException(source, nameof(source)); Error.ThrowArgumentNullException(source, nameof(source));
return Count<TSource>.InvokeAsync(source, cancellationToken); return Count.InvokeAsync(source, cancellationToken);
} }
public static UniTask<Int32> CountAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken = default) public static UniTask<Int32> CountAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken = default)
@ -18,7 +18,7 @@ namespace Cysharp.Threading.Tasks.Linq
Error.ThrowArgumentNullException(source, nameof(source)); Error.ThrowArgumentNullException(source, nameof(source));
Error.ThrowArgumentNullException(predicate, nameof(predicate)); Error.ThrowArgumentNullException(predicate, nameof(predicate));
return Count<TSource>.InvokeAsync(source, predicate, cancellationToken); return Count.InvokeAsync(source, predicate, cancellationToken);
} }
public static UniTask<Int32> CountAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default) public static UniTask<Int32> CountAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
@ -26,7 +26,7 @@ namespace Cysharp.Threading.Tasks.Linq
Error.ThrowArgumentNullException(source, nameof(source)); Error.ThrowArgumentNullException(source, nameof(source));
Error.ThrowArgumentNullException(predicate, nameof(predicate)); Error.ThrowArgumentNullException(predicate, nameof(predicate));
return Count<TSource>.InvokeAsync(source, predicate, cancellationToken); return Count.InvokeAsync(source, predicate, cancellationToken);
} }
public static UniTask<Int32> CountAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default) public static UniTask<Int32> CountAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
@ -34,13 +34,13 @@ namespace Cysharp.Threading.Tasks.Linq
Error.ThrowArgumentNullException(source, nameof(source)); Error.ThrowArgumentNullException(source, nameof(source));
Error.ThrowArgumentNullException(predicate, nameof(predicate)); Error.ThrowArgumentNullException(predicate, nameof(predicate));
return Count<TSource>.InvokeAsync(source, predicate, cancellationToken); return Count.InvokeAsync(source, predicate, cancellationToken);
} }
} }
internal static class Count<TSource> internal static class Count
{ {
internal static async UniTask<int> InvokeAsync(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken) internal static async UniTask<int> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
{ {
var count = 0; var count = 0;
@ -63,7 +63,7 @@ namespace Cysharp.Threading.Tasks.Linq
return count; return count;
} }
internal static async UniTask<int> InvokeAsync(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken) internal static async UniTask<int> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken)
{ {
var count = 0; var count = 0;
@ -89,7 +89,7 @@ namespace Cysharp.Threading.Tasks.Linq
return count; return count;
} }
internal static async UniTask<int> InvokeAsync(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken) internal static async UniTask<int> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken)
{ {
var count = 0; var count = 0;
@ -115,7 +115,7 @@ namespace Cysharp.Threading.Tasks.Linq
return count; return count;
} }
internal static async UniTask<int> InvokeAsync(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken) internal static async UniTask<int> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken)
{ {
var count = 0; var count = 0;

View File

@ -10,7 +10,7 @@ namespace Cysharp.Threading.Tasks.Linq
{ {
Error.ThrowArgumentNullException(source, nameof(source)); Error.ThrowArgumentNullException(source, nameof(source));
return LongCount<TSource>.InvokeAsync(source, cancellationToken); return LongCount.InvokeAsync(source, cancellationToken);
} }
public static UniTask<long> LongCountAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken = default) public static UniTask<long> LongCountAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken = default)
@ -18,7 +18,7 @@ namespace Cysharp.Threading.Tasks.Linq
Error.ThrowArgumentNullException(source, nameof(source)); Error.ThrowArgumentNullException(source, nameof(source));
Error.ThrowArgumentNullException(predicate, nameof(predicate)); Error.ThrowArgumentNullException(predicate, nameof(predicate));
return LongCount<TSource>.InvokeAsync(source, predicate, cancellationToken); return LongCount.InvokeAsync(source, predicate, cancellationToken);
} }
public static UniTask<long> LongCountAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default) public static UniTask<long> LongCountAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
@ -26,7 +26,7 @@ namespace Cysharp.Threading.Tasks.Linq
Error.ThrowArgumentNullException(source, nameof(source)); Error.ThrowArgumentNullException(source, nameof(source));
Error.ThrowArgumentNullException(predicate, nameof(predicate)); Error.ThrowArgumentNullException(predicate, nameof(predicate));
return LongCount<TSource>.InvokeAsync(source, predicate, cancellationToken); return LongCount.InvokeAsync(source, predicate, cancellationToken);
} }
public static UniTask<long> LongCountAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default) public static UniTask<long> LongCountAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
@ -34,13 +34,13 @@ namespace Cysharp.Threading.Tasks.Linq
Error.ThrowArgumentNullException(source, nameof(source)); Error.ThrowArgumentNullException(source, nameof(source));
Error.ThrowArgumentNullException(predicate, nameof(predicate)); Error.ThrowArgumentNullException(predicate, nameof(predicate));
return LongCount<TSource>.InvokeAsync(source, predicate, cancellationToken); return LongCount.InvokeAsync(source, predicate, cancellationToken);
} }
} }
internal static class LongCount<TSource> internal static class LongCount
{ {
internal static async UniTask<long> InvokeAsync(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken) internal static async UniTask<long> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
{ {
long count = 0; long count = 0;
@ -63,7 +63,7 @@ namespace Cysharp.Threading.Tasks.Linq
return count; return count;
} }
internal static async UniTask<long> InvokeAsync(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken) internal static async UniTask<long> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken)
{ {
long count = 0; long count = 0;
@ -89,7 +89,7 @@ namespace Cysharp.Threading.Tasks.Linq
return count; return count;
} }
internal static async UniTask<long> InvokeAsync(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken) internal static async UniTask<long> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken)
{ {
long count = 0; long count = 0;
@ -115,7 +115,7 @@ namespace Cysharp.Threading.Tasks.Linq
return count; return count;
} }
internal static async UniTask<long> InvokeAsync(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken) internal static async UniTask<long> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken)
{ {
long count = 0; long count = 0;

View File

@ -1,775 +1,87 @@
namespace Cysharp.Threading.Tasks.Linq using Cysharp.Threading.Tasks.Internal;
using System;
using System.Collections.Generic;
using System.Threading;
namespace Cysharp.Threading.Tasks.Linq
{ {
internal sealed class SequenceEqual public static partial class UniTaskAsyncEnumerable
{ {
public static UniTask<Boolean> SequenceEqualAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> first, IUniTaskAsyncEnumerable<TSource> second, CancellationToken cancellationToken = default)
{
return SequenceEqualAsync(first, second, EqualityComparer<TSource>.Default, cancellationToken);
} }
public static UniTask<Boolean> SequenceEqualAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> first, IUniTaskAsyncEnumerable<TSource> second, IEqualityComparer<TSource> comparer, CancellationToken cancellationToken = default)
{
Error.ThrowArgumentNullException(first, nameof(first));
Error.ThrowArgumentNullException(second, nameof(second));
Error.ThrowArgumentNullException(comparer, nameof(comparer));
return SequenceEqual.InvokeAsync(first, second, comparer, cancellationToken);
}
} }
internal static class SequenceEqual
{
internal static async UniTask<bool> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> first, IUniTaskAsyncEnumerable<TSource> second, IEqualityComparer<TSource> comparer, CancellationToken cancellationToken)
{
var e1 = first.GetAsyncEnumerator(cancellationToken);
try
{
var e2 = second.GetAsyncEnumerator(cancellationToken);
try
{
while (true)
{
if (await e1.MoveNextAsync())
{
if (await e2.MoveNextAsync())
{
if (comparer.Equals(e1.Current, e2.Current))
{
continue;
}
else
{
return false;
}
}
else
{
// e2 is finished, but e1 has value
return false;
}
}
else
{
// e1 is finished, e2?
if (await e2.MoveNextAsync())
{
return false;
}
else
{
return true;
}
}
}
}
finally
{
if (e2 != null)
{
await e2.DisposeAsync();
}
}
}
finally
{
if (e1 != null)
{
await e1.DisposeAsync();
}
}
}
}
}

View File

@ -66,41 +66,6 @@ namespace ___Dummy
throw new NotImplementedException(); throw new NotImplementedException();
} }
public static UniTask<Boolean> AllAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public static UniTask<Boolean> AllAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public static UniTask<Boolean> AllAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public static UniTask<Boolean> AnyAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public static UniTask<Boolean> AnyAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public static UniTask<Boolean> AnyAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public static UniTask<Boolean> AnyAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public static IUniTaskAsyncEnumerable<TSource> Append<TSource>(this IUniTaskAsyncEnumerable<TSource> source, TSource element) public static IUniTaskAsyncEnumerable<TSource> Append<TSource>(this IUniTaskAsyncEnumerable<TSource> source, TSource element)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
@ -122,15 +87,7 @@ namespace ___Dummy
throw new NotImplementedException(); throw new NotImplementedException();
} }
public static UniTask<Boolean> ContainsAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, TSource value, IEqualityComparer<TSource> comparer, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public static UniTask<Boolean> ContainsAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, TSource value, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public static IUniTaskAsyncEnumerable<TSource> DefaultIfEmpty<TSource>(this IUniTaskAsyncEnumerable<TSource> source) public static IUniTaskAsyncEnumerable<TSource> DefaultIfEmpty<TSource>(this IUniTaskAsyncEnumerable<TSource> source)
{ {
@ -496,15 +453,6 @@ namespace ___Dummy
throw new NotImplementedException(); throw new NotImplementedException();
} }
public static UniTask<Boolean> SequenceEqualAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> first, IUniTaskAsyncEnumerable<TSource> second, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public static UniTask<Boolean> SequenceEqualAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> first, IUniTaskAsyncEnumerable<TSource> second, IEqualityComparer<TSource> comparer, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public static IUniTaskAsyncEnumerable<TSource> Skip<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Int32 count) public static IUniTaskAsyncEnumerable<TSource> Skip<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Int32 count)
{ {

View File

@ -0,0 +1,112 @@
using Cysharp.Threading.Tasks;
using Cysharp.Threading.Tasks.Linq;
using FluentAssertions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using System.Threading.Tasks;
using Xunit;
namespace NetCoreTests.Linq
{
public class AllAny
{
[Theory]
[InlineData(0, 0)]
[InlineData(1, 1)]
[InlineData(1, 2)]
[InlineData(1, 3)]
[InlineData(0, 10)]
[InlineData(0, 11)]
public async Task AllTest(int start, int count)
{
var range = Enumerable.Range(start, count);
var x = await range.ToUniTaskAsyncEnumerable().AllAsync(x => x % 2 == 0);
var y = range.All(x => x % 2 == 0);
x.Should().Be(y);
}
[Theory]
[InlineData(0, 0)]
[InlineData(1, 1)]
[InlineData(1, 2)]
[InlineData(1, 3)]
[InlineData(0, 10)]
[InlineData(0, 11)]
public async Task AnyTest(int start, int count)
{
var range = Enumerable.Range(start, count);
{
var x = await range.ToUniTaskAsyncEnumerable().AnyAsync();
var y = range.Any();
x.Should().Be(y);
}
{
var x = await range.ToUniTaskAsyncEnumerable().AnyAsync(x => x % 2 == 0);
var y = range.Any(x => x % 2 == 0);
x.Should().Be(y);
}
}
[Theory]
[InlineData(0, 0)]
[InlineData(1, 1)]
[InlineData(1, 2)]
[InlineData(1, 3)]
[InlineData(0, 10)]
[InlineData(0, 11)]
public async Task ContainsTest(int start, int count)
{
var range = Enumerable.Range(start, count);
foreach (var c in Enumerable.Range(0, 15))
{
var x = await range.ToUniTaskAsyncEnumerable().ContainsAsync(c);
var y = range.Contains(c);
x.Should().Be(y);
}
}
[Fact]
public async Task SequenceEqual()
{
// empty and empty
(await new int[0].ToUniTaskAsyncEnumerable().SequenceEqualAsync(new int[0].ToUniTaskAsyncEnumerable())).Should().BeTrue();
(new int[0].SequenceEqual(new int[0])).Should().BeTrue();
// empty and exists
(await new int[0].ToUniTaskAsyncEnumerable().SequenceEqualAsync(new int[] { 1 }.ToUniTaskAsyncEnumerable())).Should().BeFalse();
(new int[0].SequenceEqual(new int[] { 1 })).Should().BeFalse();
// exists and empty
(await new int[] { 1 }.ToUniTaskAsyncEnumerable().SequenceEqualAsync(new int[0].ToUniTaskAsyncEnumerable())).Should().BeFalse();
(new int[] { 1 }.SequenceEqual(new int[] { })).Should().BeFalse();
// samelength same value
(await new int[] { 1, 2, 3 }.ToUniTaskAsyncEnumerable().SequenceEqualAsync(new int[] { 1, 2, 3 }.ToUniTaskAsyncEnumerable())).Should().BeTrue();
(new int[] { 1, 2, 3 }.SequenceEqual(new int[] { 1, 2, 3 })).Should().BeTrue();
// samelength different value(first)
(await new int[] { 5, 2, 3 }.ToUniTaskAsyncEnumerable().SequenceEqualAsync(new int[] { 1, 2, 3 }.ToUniTaskAsyncEnumerable())).Should().BeFalse();
// samelength different value(middle)
(await new int[] { 1, 2, 3 }.ToUniTaskAsyncEnumerable().SequenceEqualAsync(new int[] { 1, 5, 3 }.ToUniTaskAsyncEnumerable())).Should().BeFalse();
// samelength different value(last)
(await new int[] { 1, 2, 3 }.ToUniTaskAsyncEnumerable().SequenceEqualAsync(new int[] { 1, 2, 5 }.ToUniTaskAsyncEnumerable())).Should().BeFalse();
// left is long
(await new int[] { 1, 2, 3, 4 }.ToUniTaskAsyncEnumerable().SequenceEqualAsync(new int[] { 1, 2, 3 }.ToUniTaskAsyncEnumerable())).Should().BeFalse();
(new int[] { 1, 2, 3, 4 }.SequenceEqual(new int[] { 1, 2, 3 })).Should().BeFalse();
// right is long
(await new int[] { 1, 2, 3 }.ToUniTaskAsyncEnumerable().SequenceEqualAsync(new int[] { 1, 2, 3, 4 }.ToUniTaskAsyncEnumerable())).Should().BeFalse();
(new int[] { 1, 2, 3 }.SequenceEqual(new int[] { 1, 2, 3, 4 })).Should().BeFalse();
}
}
}