Summary

Class:E_AsyncEnumeration
Assembly:AsyncEnumeration.Abstractions
File(s):/repo-dir/contents/Source/Code/AsyncEnumeration.Abstractions/aLINQ/Aggregate.cs
/repo-dir/contents/Source/Code/AsyncEnumeration.Abstractions/aLINQ/AnyAll.cs
/repo-dir/contents/Source/Code/AsyncEnumeration.Abstractions/aLINQ/First.cs
/repo-dir/contents/Source/Code/AsyncEnumeration.Abstractions/aLINQ/OfType.cs
/repo-dir/contents/Source/Code/AsyncEnumeration.Abstractions/aLINQ/Select.cs
/repo-dir/contents/Source/Code/AsyncEnumeration.Abstractions/aLINQ/SelectMany.cs
/repo-dir/contents/Source/Code/AsyncEnumeration.Abstractions/aLINQ/Skip.cs
/repo-dir/contents/Source/Code/AsyncEnumeration.Abstractions/aLINQ/Take.cs
/repo-dir/contents/Source/Code/AsyncEnumeration.Abstractions/aLINQ/ToSynchronous.cs
/repo-dir/contents/Source/Code/AsyncEnumeration.Abstractions/aLINQ/Where.cs
/repo-dir/contents/Source/Code/AsyncEnumeration.Abstractions/Enumeration.cs
Covered lines:64
Uncovered lines:64
Coverable lines:128
Total lines:1690
Line coverage:50%
Branch coverage:41.9%
Tag:7d9974899246b95481b7aa9cd3a1462ae2a67c91

Coverage History

Metrics

MethodCyclomatic complexity NPath complexity Sequence coverage Branch coverage
AggregateAsync(...)201%0.5%
AggregateAsync(...)201%0.5%
AggregateAsync(...)201%0.5%
AggregateAsync(...)201%0.5%
AnyAsync(...)201%0.5%
AnyAsync(...)201%0.5%
AnyAsync(...)201%0.5%
AllAsync(...)201%0.5%
AllAsync(...)201%0.5%
FirstAsync(...)201%0.5%
FirstOrDefaultAsync(...)201%0.5%
Of(...)101%0%
Select(...)201%0.5%
Select(...)201%0.5%
SelectMany(...)201%0.5%
SelectMany(...)201%0.5%
SelectMany(...)201%0.5%
SelectMany(...)201%0.5%
Skip(...)201%0.5%
Skip(...)201%0.5%
SkipWhile(...)201%0.5%
SkipWhile(...)201%0.5%
Take(...)201%0.5%
Take(...)201%0.5%
TakeWhile(...)201%0.5%
TakeWhile(...)201%0.5%
AddToCollectionAsync(...)101%0%
AddToCollectionAsync(...)100%0%
ToArrayAsync()401%1%
ToListAsync()601%1%
ToDictionaryAsync()400%0%
ToDictionaryAsync()200%0%
>c__DisplayClass31_0`3/<<ToDictionaryAsync()800%0%
AddToConcurrentCollectionAsync(...)100%0%
AddToConcurrentCollectionAsync(...)100%0%
ToConcurrentBagAsync()600%0%
ToConcurrentQueueAsync()600%0%
ToConcurrentStackAsync()600%0%
ToConcurrentBagAsync()200%0%
>c__DisplayClass37_0`2/<<ToConcurrentBagAsync()400%0%
ToConcurrentQueueAsync()200%0%
>c__DisplayClass38_0`2/<<ToConcurrentQueueAsync()400%0%
ToConcurrentStackAsync()200%0%
>c__DisplayClass39_0`2/<<ToConcurrentStackAsync()400%0%
ToConcurrentDictionaryAsync()600%0%
ToConcurrentDictionaryAsync()400%0%
>c__DisplayClass41_0`3/<<ToConcurrentDictionaryAsync()800%0%
Where(...)201%0.5%
Where(...)201%0.5%
EnumerateAsync()2401%0.75%
EnumerateAsync()3001%0.767%
EnumerateAsync(...)101%0%
EnumerateAsync(...)101%0%
EnumerateAsync(...)101%0%

File(s)

/repo-dir/contents/Source/Code/AsyncEnumeration.Abstractions/aLINQ/Aggregate.cs

#LineLine coverage
 1/*
 2 * Copyright 2018 Stanislav Muhametsin. All rights Reserved.
 3 *
 4 * Licensed  under the  Apache License,  Version 2.0  (the "License");
 5 * you may not use  this file  except in  compliance with the License.
 6 * You may obtain a copy of the License at
 7 *
 8 *   http://www.apache.org/licenses/LICENSE-2.0
 9 *
 10 * Unless required by applicable law or agreed to in writing, software
 11 * distributed  under the  License is distributed on an "AS IS" BASIS,
 12 * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
 13 * implied.
 14 *
 15 * See the License for the specific language governing permissions and
 16 * limitations under the License.
 17 */
 18using AsyncEnumeration.Abstractions;
 19using System;
 20using System.Collections.Generic;
 21using System.Text;
 22using System.Threading;
 23using System.Threading.Tasks;
 24using UtilPack;
 25
 26namespace AsyncEnumeration.Abstractions
 27{
 28   public partial interface IAsyncProvider
 29   {
 30      /// <summary>
 31      /// Similarly to <see cref="System.Linq.Enumerable.Aggregate{TSource}(IEnumerable{TSource}, Func{TSource, TSource,
 32      /// </summary>
 33      /// <typeparam name="T">The type of elements being enumerated.</typeparam>
 34      /// <param name="source">This <see cref="IAsyncEnumerable{T}"/>.</param>
 35      /// <param name="func">The synchronous callback function to perform aggregation. First argument is previous elemen
 36      /// <returns>An aggregated value.</returns>
 37      /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 38      /// <exception cref="ArgumentNullException">If <paramref name="func"/> is <c>null</c>.</exception>
 39      /// <exception cref="InvalidOperationException">If this <see cref="IAsyncEnumerable{T}"/> does not contain at leas
 40      Task<T> AggregateAsync<T>( IAsyncEnumerable<T> source, Func<T, T, T> func );
 41
 42      /// <summary>
 43      /// Similarly to <see cref="System.Linq.Enumerable.Aggregate{TSource}(IEnumerable{TSource}, Func{TSource, TSource,
 44      /// </summary>
 45      /// <typeparam name="T">The type of elements being enumerated.</typeparam>
 46      /// <param name="source">This <see cref="IAsyncEnumerable{T}"/>.</param>
 47      /// <param name="asyncFunc">The potentially asynchronous callback function to perform aggregation. First argument 
 48      /// <returns>An aggregated value.</returns>
 49      /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 50      /// <exception cref="ArgumentNullException">If <paramref name="asyncFunc"/> is <c>null</c>.</exception>
 51      /// <exception cref="InvalidOperationException">If this <see cref="IAsyncEnumerable{T}"/> does not contain at leas
 52      Task<T> AggregateAsync<T>( IAsyncEnumerable<T> source, Func<T, T, ValueTask<T>> asyncFunc );
 53
 54      /// <summary>
 55      /// Similarly to <see cref="System.Linq.Enumerable.Aggregate{TSource, TAccumulate}(IEnumerable{TSource}, TAccumula
 56      /// The type of the intermediate and return value is different than the type of elements in this <see cref="IAsync
 57      /// </summary>
 58      /// <typeparam name="T">The type of elements being enumerated.</typeparam>
 59      /// <typeparam name="TResult">The type of intermediate and result values.</typeparam>
 60      /// <param name="source">This <see cref="IAsyncEnumerable{T}"/>.</param>
 61      /// <param name="func">The synchronous calllback function to perform aggregation. First argument is intermediate v
 62      /// <param name="seed">The optional initial value for first argument of <paramref name="func"/> callback.</param>
 63      /// <returns>An aggregated value.</returns>
 64      /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 65      /// <exception cref="ArgumentNullException">If <paramref name="func"/> is <c>null</c>.</exception>
 66      Task<TResult> AggregateAsync<T, TResult>( IAsyncEnumerable<T> source, Func<TResult, T, TResult> func, TResult seed
 67
 68      /// <summary>
 69      /// Similarly to <see cref="System.Linq.Enumerable.Aggregate{TSource, TAccumulate}(IEnumerable{TSource}, TAccumula
 70      /// The type of the intermediate and return value is different than the type of elements in this <see cref="IAsync
 71      /// </summary>
 72      /// <typeparam name="T">The type of elements being enumerated.</typeparam>
 73      /// <typeparam name="TResult">The type of intermediate and result values.</typeparam>
 74      /// <param name="source">This <see cref="IAsyncEnumerable{T}"/>.</param>
 75      /// <param name="asyncFunc">The potentially asynchronous calllback function to perform aggregation. First argument
 76      /// <param name="seed">The optional initial value for first argument of <paramref name="asyncFunc"/> callback.</pa
 77      /// <returns>An aggregated value.</returns>
 78      /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 79      /// <exception cref="ArgumentNullException">If <paramref name="asyncFunc"/> is <c>null</c>.</exception>
 80      Task<TResult> AggregateAsync<T, TResult>( IAsyncEnumerable<T> source, Func<TResult, T, ValueTask<TResult>> asyncFu
 81   }
 82
 83
 84}
 85
 86
 87public static partial class E_AsyncEnumeration
 88{
 89
 90
 91   /// <summary>
 92   /// Similarly to <see cref="System.Linq.Enumerable.Aggregate{TSource}(IEnumerable{TSource}, Func{TSource, TSource, TS
 93   /// </summary>
 94   /// <typeparam name="T">The type of elements being enumerated.</typeparam>
 95   /// <param name="source">This <see cref="IAsyncEnumerable{T}"/>.</param>
 96   /// <param name="func">The synchronous callback function to perform aggregation. First argument is previous element, 
 97   /// <returns>An aggregated value.</returns>
 98   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 99   /// <exception cref="ArgumentNullException">If <paramref name="func"/> is <c>null</c>.</exception>
 100   /// <exception cref="InvalidOperationException">If this <see cref="IAsyncEnumerable{T}"/> does not contain at least o
 101   public static Task<T> AggregateAsync<T>( this IAsyncEnumerable<T> source, Func<T, T, T> func )
 2102      => ( source.AsyncProvider ?? throw AsyncProviderUtilities.NoAsyncProviderException() ).AggregateAsync( source, fun
 103
 104   /// <summary>
 105   /// Similarly to <see cref="System.Linq.Enumerable.Aggregate{TSource}(IEnumerable{TSource}, Func{TSource, TSource, TS
 106   /// </summary>
 107   /// <typeparam name="T">The type of elements being enumerated.</typeparam>
 108   /// <param name="source">This <see cref="IAsyncEnumerable{T}"/>.</param>
 109   /// <param name="asyncFunc">The potentially asynchronous callback function to perform aggregation. First argument is 
 110   /// <returns>An aggregated value.</returns>
 111   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 112   /// <exception cref="ArgumentNullException">If <paramref name="asyncFunc"/> is <c>null</c>.</exception>
 113   /// <exception cref="InvalidOperationException">If this <see cref="IAsyncEnumerable{T}"/> does not contain at least o
 114   public static Task<T> AggregateAsync<T>( this IAsyncEnumerable<T> source, Func<T, T, ValueTask<T>> asyncFunc )
 2115      => ( source.AsyncProvider ?? throw AsyncProviderUtilities.NoAsyncProviderException() ).AggregateAsync( source, asy
 116
 117   /// <summary>
 118   /// Similarly to <see cref="System.Linq.Enumerable.Aggregate{TSource, TAccumulate}(IEnumerable{TSource}, TAccumulate,
 119   /// The type of the intermediate and return value is different than the type of elements in this <see cref="IAsyncEnu
 120   /// </summary>
 121   /// <typeparam name="T">The type of elements being enumerated.</typeparam>
 122   /// <typeparam name="TResult">The type of intermediate and result values.</typeparam>
 123   /// <param name="source">This <see cref="IAsyncEnumerable{T}"/>.</param>
 124   /// <param name="func">The synchronous calllback function to perform aggregation. First argument is intermediate valu
 125   /// <param name="seed">The optional initial value for first argument of <paramref name="func"/> callback.</param>
 126   /// <returns>An aggregated value.</returns>
 127   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 128   /// <exception cref="ArgumentNullException">If <paramref name="func"/> is <c>null</c>.</exception>
 129   public static Task<TResult> AggregateAsync<T, TResult>( this IAsyncEnumerable<T> source, Func<TResult, T, TResult> fu
 2130      => ( source.AsyncProvider ?? throw AsyncProviderUtilities.NoAsyncProviderException() ).AggregateAsync( source, fun
 131
 132   /// <summary>
 133   /// Similarly to <see cref="System.Linq.Enumerable.Aggregate{TSource, TAccumulate}(IEnumerable{TSource}, TAccumulate,
 134   /// The type of the intermediate and return value is different than the type of elements in this <see cref="IAsyncEnu
 135   /// </summary>
 136   /// <typeparam name="T">The type of elements being enumerated.</typeparam>
 137   /// <typeparam name="TResult">The type of intermediate and result values.</typeparam>
 138   /// <param name="source">This <see cref="IAsyncEnumerable{T}"/>.</param>
 139   /// <param name="asyncFunc">The potentially asynchronous calllback function to perform aggregation. First argument is
 140   /// <param name="seed">The optional initial value for first argument of <paramref name="asyncFunc"/> callback.</param
 141   /// <returns>An aggregated value.</returns>
 142   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 143   /// <exception cref="ArgumentNullException">If <paramref name="asyncFunc"/> is <c>null</c>.</exception>
 144   public static Task<TResult> AggregateAsync<T, TResult>( this IAsyncEnumerable<T> source, Func<TResult, T, ValueTask<T
 2145      => ( source.AsyncProvider ?? throw AsyncProviderUtilities.NoAsyncProviderException() ).AggregateAsync( source, asy
 146}

/repo-dir/contents/Source/Code/AsyncEnumeration.Abstractions/aLINQ/AnyAll.cs

#LineLine coverage
 1/*
 2 * Copyright 2018 Stanislav Muhametsin. All rights Reserved.
 3 *
 4 * Licensed  under the  Apache License,  Version 2.0  (the "License");
 5 * you may not use  this file  except in  compliance with the License.
 6 * You may obtain a copy of the License at
 7 *
 8 *   http://www.apache.org/licenses/LICENSE-2.0
 9 *
 10 * Unless required by applicable law or agreed to in writing, software
 11 * distributed  under the  License is distributed on an "AS IS" BASIS,
 12 * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
 13 * implied.
 14 *
 15 * See the License for the specific language governing permissions and
 16 * limitations under the License.
 17 */
 18using AsyncEnumeration.Abstractions;
 19using System;
 20using System.Collections.Generic;
 21using System.Text;
 22using System.Threading.Tasks;
 23using UtilPack;
 24
 25namespace AsyncEnumeration.Abstractions
 26{
 27   public partial interface IAsyncProvider
 28   {
 29      /// <summary>
 30      /// Similarly to <see cref="System.Linq.Enumerable.Any{TSource}(IEnumerable{TSource})"/>, this method checks wheth
 31      /// </summary>
 32      /// <typeparam name="T">The type of elements being enumerated.</typeparam>
 33      /// <param name="source">This <see cref="IAsyncEnumerable{T}"/>.</param>
 34      /// <returns>Potentially asynchronously returns <c>true</c> if this <see cref="IAsyncEnumerable{T}"/> has at least
 35      /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 36      /// <seealso cref="System.Linq.Enumerable.Any{TSource}(IEnumerable{TSource})"/>
 37      Task<Boolean> AnyAsync<T>( IAsyncEnumerable<T> source );
 38
 39      /// <summary>
 40      /// Similarly to <see cref="System.Linq.Enumerable.Any{TSource}(IEnumerable{TSource}, Func{TSource, Boolean})"/>, 
 41      /// </summary>
 42      /// <typeparam name="T">The type of elements being enumerated.</typeparam>
 43      /// <param name="source">This <see cref="IAsyncEnumerable{T}"/>.</param>
 44      /// <param name="predicate">The synchronous callback to check whether an element satifies some condition. If <c>nu
 45      /// <returns>Potentially asynchronously returns <c>true</c> if this <see cref="IAsyncEnumerable{T}"/> has at least
 46      /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 47      /// <seealso cref="System.Linq.Enumerable.Any{TSource}(IEnumerable{TSource}, Func{TSource, Boolean})"/>
 48      Task<Boolean> AnyAsync<T>( IAsyncEnumerable<T> source, Func<T, Boolean> predicate );
 49
 50      /// <summary>
 51      /// Similarly to <see cref="System.Linq.Enumerable.Any{TSource}(IEnumerable{TSource}, Func{TSource, Boolean})"/>, 
 52      /// </summary>
 53      /// <typeparam name="T">The type of elements being enumerated.</typeparam>
 54      /// <param name="source">This <see cref="IAsyncEnumerable{T}"/>.</param>
 55      /// <param name="asyncPredicate">The potentially asynchronous callback to check whether an element satifies some c
 56      /// <returns>Potentially asynchronously returns <c>true</c> if this <see cref="IAsyncEnumerable{T}"/> has at least
 57      /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 58      /// <seealso cref="System.Linq.Enumerable.Any{TSource}(IEnumerable{TSource}, Func{TSource, Boolean})"/>
 59      Task<Boolean> AnyAsync<T>( IAsyncEnumerable<T> source, Func<T, ValueTask<Boolean>> asyncPredicate );
 60
 61      /// <summary>
 62      /// Checks that all items in this <see cref="IAsyncEnumerable{T}"/> adher to condition checked by given synchronou
 63      /// </summary>
 64      /// <typeparam name="T">The type of elements being enumerated.</typeparam>
 65      /// <param name="source">This <see cref="IAsyncEnumerable{T}"/>.</param>
 66      /// <param name="predicate">The synchronous callback to check whether an element satifies some condition.</param>
 67      /// <returns>Potentially asynchronously returns <c>true</c> if this <see cref="IAsyncEnumerable{T}"/> is empty, or
 68      /// <seealso cref="System.Linq.Enumerable.All{TSource}(IEnumerable{TSource}, Func{TSource, Boolean})"/>
 69      /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 70      /// <exception cref="ArgumentNullException">If <paramref name="predicate"/> is <c>null</c>.</exception>
 71      Task<Boolean> AllAsync<T>( IAsyncEnumerable<T> source, Func<T, Boolean> predicate );
 72
 73      /// <summary>
 74      /// Checks that all items in this <see cref="IAsyncEnumerable{T}"/> adher to condition checked by given potentiall
 75      /// </summary>
 76      /// <typeparam name="T">The type of elements being enumerated.</typeparam>
 77      /// <param name="source">This <see cref="IAsyncEnumerable{T}"/>.</param>
 78      /// <param name="asyncPredicate">The potentially asynchronous callback to check whether an element satifies some c
 79      /// <returns>Potentially asynchronously returns <c>true</c> if this <see cref="IAsyncEnumerable{T}"/> is empty, or
 80      /// <seealso cref="System.Linq.Enumerable.All{TSource}(IEnumerable{TSource}, Func{TSource, Boolean})"/>
 81      /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 82      /// <exception cref="ArgumentNullException">If <paramref name="asyncPredicate"/> is <c>null</c>.</exception>
 83      Task<Boolean> AllAsync<T>( IAsyncEnumerable<T> source, Func<T, ValueTask<Boolean>> asyncPredicate );
 84   }
 85
 86
 87}
 88
 89public static partial class E_AsyncEnumeration
 90{
 91   /// <summary>
 92   /// Similarly to <see cref="System.Linq.Enumerable.Any{TSource}(IEnumerable{TSource})"/>, this method checks whether 
 93   /// </summary>
 94   /// <typeparam name="T">The type of elements being enumerated.</typeparam>
 95   /// <param name="source">This <see cref="IAsyncEnumerable{T}"/>.</param>
 96   /// <returns>Potentially asynchronously returns <c>true</c> if this <see cref="IAsyncEnumerable{T}"/> has at least on
 97   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 98   /// <seealso cref="System.Linq.Enumerable.Any{TSource}(IEnumerable{TSource})"/>
 99   public static Task<Boolean> AnyAsync<T>( this IAsyncEnumerable<T> source )
 2100      => ( source.AsyncProvider ?? throw AsyncProviderUtilities.NoAsyncProviderException() ).AnyAsync( source );
 101
 102   /// <summary>
 103   /// Similarly to <see cref="System.Linq.Enumerable.Any{TSource}(IEnumerable{TSource}, Func{TSource, Boolean})"/>, thi
 104   /// </summary>
 105   /// <typeparam name="T">The type of elements being enumerated.</typeparam>
 106   /// <param name="source">This <see cref="IAsyncEnumerable{T}"/>.</param>
 107   /// <param name="predicate">The synchronous callback to check whether an element satifies some condition. If <c>null<
 108   /// <returns>Potentially asynchronously returns <c>true</c> if this <see cref="IAsyncEnumerable{T}"/> has at least on
 109   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 110   /// <seealso cref="System.Linq.Enumerable.Any{TSource}(IEnumerable{TSource}, Func{TSource, Boolean})"/>
 111   public static Task<Boolean> AnyAsync<T>( this IAsyncEnumerable<T> source, Func<T, Boolean> predicate )
 3112      => ( source.AsyncProvider ?? throw AsyncProviderUtilities.NoAsyncProviderException() ).AnyAsync( source, predicate
 113
 114   /// <summary>
 115   /// Similarly to <see cref="System.Linq.Enumerable.Any{TSource}(IEnumerable{TSource}, Func{TSource, Boolean})"/>, thi
 116   /// </summary>
 117   /// <typeparam name="T">The type of elements being enumerated.</typeparam>
 118   /// <param name="source">This <see cref="IAsyncEnumerable{T}"/>.</param>
 119   /// <param name="asyncPredicate">The potentially asynchronous callback to check whether an element satifies some cond
 120   /// <returns>Potentially asynchronously returns <c>true</c> if this <see cref="IAsyncEnumerable{T}"/> has at least on
 121   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 122   /// <seealso cref="System.Linq.Enumerable.Any{TSource}(IEnumerable{TSource}, Func{TSource, Boolean})"/>
 123   public static Task<Boolean> AnyAsync<T>( this IAsyncEnumerable<T> source, Func<T, ValueTask<Boolean>> asyncPredicate 
 3124      => ( source.AsyncProvider ?? throw AsyncProviderUtilities.NoAsyncProviderException() ).AnyAsync( source, asyncPred
 125
 126   /// <summary>
 127   /// Checks that all items in this <see cref="IAsyncEnumerable{T}"/> adher to condition checked by given synchronous <
 128   /// </summary>
 129   /// <typeparam name="T">The type of elements being enumerated.</typeparam>
 130   /// <param name="source">This <see cref="IAsyncEnumerable{T}"/>.</param>
 131   /// <param name="predicate">The synchronous callback to check whether an element satifies some condition.</param>
 132   /// <returns>Potentially asynchronously returns <c>true</c> if this <see cref="IAsyncEnumerable{T}"/> is empty, or if
 133   /// <seealso cref="System.Linq.Enumerable.All{TSource}(IEnumerable{TSource}, Func{TSource, Boolean})"/>
 134   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 135   /// <exception cref="ArgumentNullException">If <paramref name="predicate"/> is <c>null</c>.</exception>
 136   public static Task<Boolean> AllAsync<T>( this IAsyncEnumerable<T> source, Func<T, Boolean> predicate )
 3137      => ( source.AsyncProvider ?? throw AsyncProviderUtilities.NoAsyncProviderException() ).AllAsync( source, predicate
 138
 139   /// <summary>
 140   /// Checks that all items in this <see cref="IAsyncEnumerable{T}"/> adher to condition checked by given potentially a
 141   /// </summary>
 142   /// <typeparam name="T">The type of elements being enumerated.</typeparam>
 143   /// <param name="source">This <see cref="IAsyncEnumerable{T}"/>.</param>
 144   /// <param name="asyncPredicate">The potentially asynchronous callback to check whether an element satifies some cond
 145   /// <returns>Potentially asynchronously returns <c>true</c> if this <see cref="IAsyncEnumerable{T}"/> is empty, or if
 146   /// <seealso cref="System.Linq.Enumerable.All{TSource}(IEnumerable{TSource}, Func{TSource, Boolean})"/>
 147   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 148   /// <exception cref="ArgumentNullException">If <paramref name="asyncPredicate"/> is <c>null</c>.</exception>
 149   public static Task<Boolean> AllAsync<T>( this IAsyncEnumerable<T> source, Func<T, ValueTask<Boolean>> asyncPredicate 
 3150      => ( source.AsyncProvider ?? throw AsyncProviderUtilities.NoAsyncProviderException() ).AllAsync( source, asyncPred
 151}

/repo-dir/contents/Source/Code/AsyncEnumeration.Abstractions/aLINQ/First.cs

#LineLine coverage
 1/*
 2 * Copyright 2017 Stanislav Muhametsin. All rights Reserved.
 3 *
 4 * Licensed  under the  Apache License,  Version 2.0  (the "License");
 5 * you may not use  this file  except in  compliance with the License.
 6 * You may obtain a copy of the License at
 7 *
 8 *   http://www.apache.org/licenses/LICENSE-2.0
 9 *
 10 * Unless required by applicable law or agreed to in writing, software
 11 * distributed  under the  License is distributed on an "AS IS" BASIS,
 12 * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
 13 * implied.
 14 *
 15 * See the License for the specific language governing permissions and
 16 * limitations under the License.
 17 */
 18using AsyncEnumeration.Abstractions;
 19using System;
 20using System.Collections.Generic;
 21using System.Text;
 22using System.Threading.Tasks;
 23
 24namespace AsyncEnumeration.Abstractions
 25{
 26   public partial interface IAsyncProvider
 27   {
 28      /// <summary>
 29      /// Asynchronously fetches the first item in this <see cref="IAsyncEnumerable{T}"/> and discards any other items.
 30      /// </summary>
 31      /// <typeparam name="T">The type of items being enumerated.</typeparam>
 32      /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 33      /// <returns>The first item returned by <see cref="IAsyncEnumerator{T}"/> of this <see cref="IAsyncEnumerable{T}"/
 34      /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 35      /// <exception cref="InvalidOperationException">If this <see cref="IAsyncEnumerable{T}"/> has no elements.</except
 36      /// <seealso cref="System.Linq.Enumerable.First{TSource}(IEnumerable{TSource})"/>
 37      Task<T> FirstAsync<T>( IAsyncEnumerable<T> enumerable );
 38
 39      /// <summary>
 40      /// Asynchronously fetches the first item in this <see cref="IAsyncEnumerable{T}"/> and discards any other items.
 41      /// If there are no items, the the default is returned for type <typeparamref name="T"/>.
 42      /// </summary>
 43      /// <typeparam name="T">The type of items being enumerated.</typeparam>
 44      /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 45      /// <returns>The first item returned by <see cref="IAsyncEnumerator{T}"/> of this <see cref="IAsyncEnumerable{T}"/
 46      /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 47      /// <seealso cref="System.Linq.Enumerable.FirstOrDefault{TSource}(IEnumerable{TSource})"/>
 48      Task<T> FirstOrDefaultAsync<T>( IAsyncEnumerable<T> enumerable );
 49
 50   }
 51
 52
 53}
 54
 55public static partial class E_AsyncEnumeration
 56{
 57   /// <summary>
 58   /// Asynchronously fetches the first item in this <see cref="IAsyncEnumerable{T}"/> and discards any other items.
 59   /// </summary>
 60   /// <typeparam name="T">The type of items being enumerated.</typeparam>
 61   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 62   /// <returns>The first item returned by <see cref="IAsyncEnumerator{T}"/> of this <see cref="IAsyncEnumerable{T}"/>.<
 63   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 64   /// <exception cref="InvalidOperationException">If this <see cref="IAsyncEnumerable{T}"/> has no elements.</exception
 65   /// <seealso cref="System.Linq.Enumerable.First{TSource}(IEnumerable{TSource})"/>
 66   public static Task<T> FirstAsync<T>( this IAsyncEnumerable<T> enumerable )
 967      => ( enumerable.AsyncProvider ?? throw AsyncProviderUtilities.NoAsyncProviderException() ).FirstAsync( enumerable 
 68
 69   /// <summary>
 70   /// Asynchronously fetches the first item in this <see cref="IAsyncEnumerable{T}"/> and discards any other items.
 71   /// If there are no items, the the default is returned for type <typeparamref name="T"/>.
 72   /// </summary>
 73   /// <typeparam name="T">The type of items being enumerated.</typeparam>
 74   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 75   /// <returns>The first item returned by <see cref="IAsyncEnumerator{T}"/> of this <see cref="IAsyncEnumerable{T}"/>, 
 76   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 77   /// <seealso cref="System.Linq.Enumerable.FirstOrDefault{TSource}(IEnumerable{TSource})"/>
 78   public static Task<T> FirstOrDefaultAsync<T>( this IAsyncEnumerable<T> enumerable )
 379      => ( enumerable.AsyncProvider ?? throw AsyncProviderUtilities.NoAsyncProviderException() ).FirstOrDefaultAsync( en
 80}

/repo-dir/contents/Source/Code/AsyncEnumeration.Abstractions/aLINQ/OfType.cs

#LineLine coverage
 1/*
 2 * Copyright 2017 Stanislav Muhametsin. All rights Reserved.
 3 *
 4 * Licensed  under the  Apache License,  Version 2.0  (the "License");
 5 * you may not use  this file  except in  compliance with the License.
 6 * You may obtain a copy of the License at
 7 *
 8 *   http://www.apache.org/licenses/LICENSE-2.0
 9 *
 10 * Unless required by applicable law or agreed to in writing, software
 11 * distributed  under the  License is distributed on an "AS IS" BASIS,
 12 * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
 13 * implied.
 14 *
 15 * See the License for the specific language governing permissions and
 16 * limitations under the License.
 17 */
 18using AsyncEnumeration.Abstractions;
 19using System;
 20using System.Collections.Generic;
 21using UtilPack;
 22
 23
 24namespace AsyncEnumeration.Abstractions
 25{
 26   public partial interface IAsyncProvider
 27   {
 28      /// <summary>
 29      /// This extension method will return <see cref="IAsyncEnumerable{T}"/> which will return only those items which a
 30      /// </summary>
 31      /// <typeparam name="T">The type of source enumerable items.</typeparam>
 32      /// <typeparam name="U">The type of target items.</typeparam>
 33      /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 34      /// <returns><see cref="IAsyncEnumerable{T}"/> which will return only those items which are of given type.</return
 35      /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 36      /// <seealso cref="System.Linq.Enumerable.OfType{TResult}(System.Collections.IEnumerable)"/>
 37      IAsyncEnumerable<U> OfType<T, U>( IAsyncEnumerable<T> enumerable );
 38   }
 39
 40   /// <summary>
 41   /// This struct exists to make life easier when using async variation of <see cref="System.Linq.Enumerable.OfType"/>,
 42   /// </summary>
 43   /// <typeparam name="T"></typeparam>
 44   public struct OfTypeInvoker<T>
 45   {
 46      private readonly IAsyncEnumerable<T> _source;
 47
 48      /// <summary>
 49      /// Creates new instance of <see cref="OfTypeInvoker{T}"/> with given <see cref="IAsyncEnumerable{T}"/>.
 50      /// </summary>
 51      /// <param name="source">The <see cref="IAsyncEnumerable{T}"/>.</param>
 52      /// <exception cref="ArgumentNullException">If <paramref name="source"/> is <c>null</c>.</exception>
 53      public OfTypeInvoker( IAsyncEnumerable<T> source )
 54      {
 55         this._source = ArgumentValidator.ValidateNotNull( nameof( source ), source );
 56      }
 57
 58      /// <summary>
 59      /// Calls <see cref="IAsyncProvider.OfType"/> with <typeparamref name="T"/> as first type parameter, and <typepara
 60      /// </summary>
 61      /// <typeparam name="U">The type to filter the elements of the <see cref="IAsyncEnumerable{T}"/> on.</typeparam>
 62      /// <returns>Filtered <see cref="IAsyncEnumerable{T}"/> with all the items of <typeparamref name="U"/>.</returns>
 63      public IAsyncEnumerable<U> Type<U>()
 64      {
 65         return (
 66            ( this._source ?? throw new InvalidOperationException( "This operation not possible on default-constructed t
 67            .AsyncProvider ?? throw AsyncProviderUtilities.NoAsyncProviderException()
 68            ).OfType<T, U>( this._source );
 69      }
 70   }
 71}
 72
 73public static partial class E_AsyncEnumeration
 74{
 75
 76   /// <summary>
 77   /// This extension method will return <see cref="IAsyncEnumerable{T}"/> which will return only those items which are 
 78   /// </summary>
 79   /// <typeparam name="T">The type of source enumerable items.</typeparam>
 80   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 81   /// <returns><see cref="IAsyncEnumerable{T}"/> which will return only those items which are of given type.</returns>
 82   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 83   /// <seealso cref="System.Linq.Enumerable.OfType{TResult}(System.Collections.IEnumerable)"/>
 84   public static OfTypeInvoker<T> Of<T>( this IAsyncEnumerable<T> enumerable )
 785      => new OfTypeInvoker<T>( ArgumentValidator.ValidateNotNullReference( enumerable ) );
 86
 87}

/repo-dir/contents/Source/Code/AsyncEnumeration.Abstractions/aLINQ/Select.cs

#LineLine coverage
 1/*
 2 * Copyright 2017 Stanislav Muhametsin. All rights Reserved.
 3 *
 4 * Licensed  under the  Apache License,  Version 2.0  (the "License");
 5 * you may not use  this file  except in  compliance with the License.
 6 * You may obtain a copy of the License at
 7 *
 8 *   http://www.apache.org/licenses/LICENSE-2.0
 9 *
 10 * Unless required by applicable law or agreed to in writing, software
 11 * distributed  under the  License is distributed on an "AS IS" BASIS,
 12 * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
 13 * implied.
 14 *
 15 * See the License for the specific language governing permissions and
 16 * limitations under the License.
 17 */
 18using AsyncEnumeration.Abstractions;
 19using System;
 20using System.Collections.Generic;
 21using System.Linq;
 22using System.Text;
 23using System.Threading.Tasks;
 24using UtilPack;
 25
 26namespace AsyncEnumeration.Abstractions
 27{
 28
 29   public partial interface IAsyncProvider
 30   {
 31      /// <summary>
 32      /// This extension method will return <see cref="IAsyncEnumerable{T}"/> which will return items as transformed by 
 33      /// </summary>
 34      /// <typeparam name="T">The type of source items.</typeparam>
 35      /// <typeparam name="U">The type of target items.</typeparam>
 36      /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 37      /// <param name="selector">The callback to transform a single item into <typeparamref name="U"/>.</param>
 38      /// <returns><see cref="IAsyncEnumerable{T}"/> which will return items as transformed by given selector callback.<
 39      /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 40      /// <exception cref="ArgumentNullException">If <paramref name="selector"/> is <c>null</c>.</exception>
 41      /// <seealso cref="Enumerable.Select{TSource, TResult}(IEnumerable{TSource}, Func{TSource, TResult})"/>
 42      IAsyncEnumerable<U> Select<T, U>( IAsyncEnumerable<T> enumerable, Func<T, U> selector );
 43
 44      /// <summary>
 45      /// This extension method will return <see cref="IAsyncEnumerable{T}"/> which will return items as transformed by 
 46      /// </summary>
 47      /// <typeparam name="T">The type of source items.</typeparam>
 48      /// <typeparam name="U">The type of target items.</typeparam>
 49      /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 50      /// <param name="asyncSelector">The callback to asynchronously transform a single item into <typeparamref name="U"
 51      /// <returns><see cref="IAsyncEnumerable{T}"/> which will return items as transformed by given selector callback.<
 52      /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 53      /// <exception cref="ArgumentNullException">If <paramref name="asyncSelector"/> is <c>null</c>.</exception>
 54      /// <seealso cref="Enumerable.Select{TSource, TResult}(IEnumerable{TSource}, Func{TSource, TResult})"/>
 55      IAsyncEnumerable<U> Select<T, U>( IAsyncEnumerable<T> enumerable, Func<T, ValueTask<U>> asyncSelector );
 56   }
 57
 58
 59}
 60
 61public static partial class E_AsyncEnumeration
 62{
 63   /// <summary>
 64   /// This extension method will return <see cref="IAsyncEnumerable{T}"/> which will return items as transformed by giv
 65   /// </summary>
 66   /// <typeparam name="T">The type of source items.</typeparam>
 67   /// <typeparam name="U">The type of target items.</typeparam>
 68   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 69   /// <param name="selector">The callback to transform a single item into <typeparamref name="U"/>.</param>
 70   /// <returns><see cref="IAsyncEnumerable{T}"/> which will return items as transformed by given selector callback.</re
 71   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 72   /// <exception cref="ArgumentNullException">If <paramref name="selector"/> is <c>null</c>.</exception>
 73   /// <seealso cref="Enumerable.Select{TSource, TResult}(IEnumerable{TSource}, Func{TSource, TResult})"/>
 74   public static IAsyncEnumerable<U> Select<T, U>( this IAsyncEnumerable<T> enumerable, Func<T, U> selector )
 475      => ( enumerable.AsyncProvider ?? throw AsyncProviderUtilities.NoAsyncProviderException() ).Select( enumerable, sel
 76
 77   /// <summary>
 78   /// This extension method will return <see cref="IAsyncEnumerable{T}"/> which will return items as transformed by giv
 79   /// </summary>
 80   /// <typeparam name="T">The type of source items.</typeparam>
 81   /// <typeparam name="U">The type of target items.</typeparam>
 82   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 83   /// <param name="asyncSelector">The callback to asynchronously transform a single item into <typeparamref name="U"/>.
 84   /// <returns><see cref="IAsyncEnumerable{T}"/> which will return items as transformed by given selector callback.</re
 85   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 86   /// <exception cref="ArgumentNullException">If <paramref name="asyncSelector"/> is <c>null</c>.</exception>
 87   /// <seealso cref="Enumerable.Select{TSource, TResult}(IEnumerable{TSource}, Func{TSource, TResult})"/>
 88   public static IAsyncEnumerable<U> Select<T, U>( this IAsyncEnumerable<T> enumerable, Func<T, ValueTask<U>> asyncSelec
 289      => ( enumerable.AsyncProvider ?? throw AsyncProviderUtilities.NoAsyncProviderException() ).Select( enumerable, asy
 90
 91}

/repo-dir/contents/Source/Code/AsyncEnumeration.Abstractions/aLINQ/SelectMany.cs

#LineLine coverage
 1/*
 2 * Copyright 2018 Stanislav Muhametsin. All rights Reserved.
 3 *
 4 * Licensed  under the  Apache License,  Version 2.0  (the "License");
 5 * you may not use  this file  except in  compliance with the License.
 6 * You may obtain a copy of the License at
 7 *
 8 *   http://www.apache.org/licenses/LICENSE-2.0
 9 *
 10 * Unless required by applicable law or agreed to in writing, software
 11 * distributed  under the  License is distributed on an "AS IS" BASIS,
 12 * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
 13 * implied.
 14 *
 15 * See the License for the specific language governing permissions and
 16 * limitations under the License.
 17 */
 18using AsyncEnumeration.Abstractions;
 19using System;
 20using System.Collections.Generic;
 21using System.Text;
 22using System.Threading;
 23using System.Threading.Tasks;
 24using UtilPack;
 25
 26namespace AsyncEnumeration.Abstractions
 27{
 28   public partial interface IAsyncProvider
 29   {
 30      /// <summary>
 31      /// This extension method will return <see cref="IAsyncEnumerable{T}"/> which will flatten the items returned by g
 32      /// </summary>
 33      /// <typeparam name="T">The type of source items.</typeparam>
 34      /// <typeparam name="U">The type of target items.</typeparam>
 35      /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 36      /// <param name="selector">The callback to transform a single item into enumerable of items of type <typeparamref 
 37      /// <returns><see cref="IAsyncEnumerable{T}"/> which will return items as flattened asynchronous enumerable.</retu
 38      /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 39      /// <exception cref="ArgumentNullException">If <paramref name="selector"/> is <c>null</c>.</exception>
 40      /// <seealso cref="System.Linq.Enumerable.SelectMany{TSource, TResult}(IEnumerable{TSource}, Func{TSource, IEnumer
 41      IAsyncEnumerable<U> SelectMany<T, U>( IAsyncEnumerable<T> enumerable, Func<T, IEnumerable<U>> selector );
 42
 43      /// <summary>
 44      /// This extension method will return <see cref="IAsyncEnumerable{T}"/> which will asynchronously flatten the item
 45      /// </summary>
 46      /// <typeparam name="T">The type of source items.</typeparam>
 47      /// <typeparam name="U">The type of target items.</typeparam>
 48      /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 49      /// <param name="asyncSelector">The callback to transform a single item into asynchronous enumerable of items of t
 50      /// <returns><see cref="IAsyncEnumerable{T}"/> which will return items as flattened asynchronous enumerable.</retu
 51      /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 52      /// <exception cref="ArgumentNullException">If <paramref name="asyncSelector"/> is <c>null</c>.</exception>
 53      /// <seealso cref="System.Linq.Enumerable.SelectMany{TSource, TResult}(IEnumerable{TSource}, Func{TSource, IEnumer
 54      IAsyncEnumerable<U> SelectMany<T, U>( IAsyncEnumerable<T> enumerable, Func<T, IAsyncEnumerable<U>> asyncSelector )
 55
 56      /// <summary>
 57      /// This extension method will return <see cref="IAsyncEnumerable{T}"/> which will asynchronously flatten the item
 58      /// </summary>
 59      /// <typeparam name="T">The type of source items.</typeparam>
 60      /// <typeparam name="U">The type of target items.</typeparam>
 61      /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 62      /// <param name="asyncSelector">The callback to asynchronously transform a single item into enumerable of items of
 63      /// <returns><see cref="IAsyncEnumerable{T}"/> which will return items as flattened asynchronous enumerable.</retu
 64      /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 65      /// <exception cref="ArgumentNullException">If <paramref name="asyncSelector"/> is <c>null</c>.</exception>
 66      /// <seealso cref="System.Linq.Enumerable.SelectMany{TSource, TResult}(IEnumerable{TSource}, Func{TSource, IEnumer
 67      IAsyncEnumerable<U> SelectMany<T, U>( IAsyncEnumerable<T> enumerable, Func<T, Task<IEnumerable<U>>> asyncSelector 
 68
 69      /// <summary>
 70      /// This extension method will return <see cref="IAsyncEnumerable{T}"/> which will asynchronously flatten the item
 71      /// </summary>
 72      /// <typeparam name="T">The type of source items.</typeparam>
 73      /// <typeparam name="U">The type of target items.</typeparam>
 74      /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 75      /// <param name="asyncSelector">The callback to asynchronously transform a single item into asynchronous enumerabl
 76      /// <returns><see cref="IAsyncEnumerable{T}"/> which will return items as flattened asynchronous enumerable.</retu
 77      /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 78      /// <exception cref="ArgumentNullException">If <paramref name="asyncSelector"/> is <c>null</c>.</exception>
 79      /// <seealso cref="System.Linq.Enumerable.SelectMany{TSource, TResult}(IEnumerable{TSource}, Func{TSource, IEnumer
 80      IAsyncEnumerable<U> SelectMany<T, U>( IAsyncEnumerable<T> enumerable, Func<T, Task<IAsyncEnumerable<U>>> asyncSele
 81   }
 82
 83}
 84
 85public static partial class E_AsyncEnumeration
 86{
 87   /// <summary>
 88   /// This extension method will return <see cref="IAsyncEnumerable{T}"/> which will flatten the items returned by give
 89   /// </summary>
 90   /// <typeparam name="T">The type of source items.</typeparam>
 91   /// <typeparam name="U">The type of target items.</typeparam>
 92   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 93   /// <param name="selector">The callback to transform a single item into enumerable of items of type <typeparamref nam
 94   /// <returns><see cref="IAsyncEnumerable{T}"/> which will return items as flattened asynchronous enumerable.</returns
 95   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 96   /// <exception cref="ArgumentNullException">If <paramref name="selector"/> is <c>null</c>.</exception>
 97   /// <seealso cref="System.Linq.Enumerable.SelectMany{TSource, TResult}(IEnumerable{TSource}, Func{TSource, IEnumerabl
 98   public static IAsyncEnumerable<U> SelectMany<T, U>( this IAsyncEnumerable<T> enumerable, Func<T, IEnumerable<U>> sele
 299      => ( enumerable.AsyncProvider ?? throw AsyncProviderUtilities.NoAsyncProviderException() ).SelectMany( enumerable,
 100
 101   /// <summary>
 102   /// This extension method will return <see cref="IAsyncEnumerable{T}"/> which will asynchronously flatten the items r
 103   /// </summary>
 104   /// <typeparam name="T">The type of source items.</typeparam>
 105   /// <typeparam name="U">The type of target items.</typeparam>
 106   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 107   /// <param name="asyncSelector">The callback to transform a single item into asynchronous enumerable of items of type
 108   /// <returns><see cref="IAsyncEnumerable{T}"/> which will return items as flattened asynchronous enumerable.</returns
 109   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 110   /// <exception cref="ArgumentNullException">If <paramref name="asyncSelector"/> is <c>null</c>.</exception>
 111   /// <seealso cref="System.Linq.Enumerable.SelectMany{TSource, TResult}(IEnumerable{TSource}, Func{TSource, IEnumerabl
 112   public static IAsyncEnumerable<U> SelectMany<T, U>( this IAsyncEnumerable<T> enumerable, Func<T, IAsyncEnumerable<U>>
 2113      => ( enumerable.AsyncProvider ?? throw AsyncProviderUtilities.NoAsyncProviderException() ).SelectMany( enumerable,
 114
 115   /// <summary>
 116   /// This extension method will return <see cref="IAsyncEnumerable{T}"/> which will asynchronously flatten the items r
 117   /// </summary>
 118   /// <typeparam name="T">The type of source items.</typeparam>
 119   /// <typeparam name="U">The type of target items.</typeparam>
 120   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 121   /// <param name="asyncSelector">The callback to asynchronously transform a single item into enumerable of items of ty
 122   /// <returns><see cref="IAsyncEnumerable{T}"/> which will return items as flattened asynchronous enumerable.</returns
 123   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 124   /// <exception cref="ArgumentNullException">If <paramref name="asyncSelector"/> is <c>null</c>.</exception>
 125   /// <seealso cref="System.Linq.Enumerable.SelectMany{TSource, TResult}(IEnumerable{TSource}, Func{TSource, IEnumerabl
 126   public static IAsyncEnumerable<U> SelectMany<T, U>( this IAsyncEnumerable<T> enumerable, Func<T, Task<IEnumerable<U>>
 2127      => ( enumerable.AsyncProvider ?? throw AsyncProviderUtilities.NoAsyncProviderException() ).SelectMany( enumerable,
 128
 129   /// <summary>
 130   /// This extension method will return <see cref="IAsyncEnumerable{T}"/> which will asynchronously flatten the items r
 131   /// </summary>
 132   /// <typeparam name="T">The type of source items.</typeparam>
 133   /// <typeparam name="U">The type of target items.</typeparam>
 134   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 135   /// <param name="asyncSelector">The callback to asynchronously transform a single item into asynchronous enumerable o
 136   /// <returns><see cref="IAsyncEnumerable{T}"/> which will return items as flattened asynchronous enumerable.</returns
 137   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 138   /// <exception cref="ArgumentNullException">If <paramref name="asyncSelector"/> is <c>null</c>.</exception>
 139   /// <seealso cref="System.Linq.Enumerable.SelectMany{TSource, TResult}(IEnumerable{TSource}, Func{TSource, IEnumerabl
 140   public static IAsyncEnumerable<U> SelectMany<T, U>( this IAsyncEnumerable<T> enumerable, Func<T, Task<IAsyncEnumerabl
 2141      => ( enumerable.AsyncProvider ?? throw AsyncProviderUtilities.NoAsyncProviderException() ).SelectMany( enumerable,
 142}

/repo-dir/contents/Source/Code/AsyncEnumeration.Abstractions/aLINQ/Skip.cs

#LineLine coverage
 1/*
 2 * Copyright 2018 Stanislav Muhametsin. All rights Reserved.
 3 *
 4 * Licensed  under the  Apache License,  Version 2.0  (the "License");
 5 * you may not use  this file  except in  compliance with the License.
 6 * You may obtain a copy of the License at
 7 *
 8 *   http://www.apache.org/licenses/LICENSE-2.0
 9 *
 10 * Unless required by applicable law or agreed to in writing, software
 11 * distributed  under the  License is distributed on an "AS IS" BASIS,
 12 * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
 13 * implied.
 14 *
 15 * See the License for the specific language governing permissions and
 16 * limitations under the License.
 17 */
 18using AsyncEnumeration.Abstractions;
 19using System;
 20using System.Collections.Generic;
 21using System.Text;
 22using System.Threading;
 23using System.Threading.Tasks;
 24using UtilPack;
 25
 26namespace AsyncEnumeration.Abstractions
 27{
 28   public partial interface IAsyncProvider
 29   {
 30      /// <summary>
 31      /// This extension method will return <see cref="IAsyncEnumerable{T}"/> which will return at most given amount of 
 32      /// </summary>
 33      /// <typeparam name="T">The type of items.</typeparam>
 34      /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 35      /// <param name="amount">The maximum amount of items to return. If zero or less, will return empty enumerable.</pa
 36      /// <returns><see cref="IAsyncEnumerable{T}"/> which will return at most given amount of items.</returns>
 37      /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 38      /// <seealso cref="System.Linq.Enumerable.Skip{TSource}(IEnumerable{TSource}, Int32)"/>
 39      IAsyncEnumerable<T> Skip<T>( IAsyncEnumerable<T> enumerable, Int32 amount );
 40
 41      /// <summary>
 42      /// This extension method will return <see cref="IAsyncEnumerable{T}"/> which will return at most given amount of 
 43      /// </summary>
 44      /// <typeparam name="T">The type of items.</typeparam>
 45      /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 46      /// <param name="amount">The maximum amount of items to return. If zero or less, will return empty enumerable.</pa
 47      /// <returns><see cref="IAsyncEnumerable{T}"/> which will return at most given amount of items.</returns>
 48      /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 49      /// <seealso cref="System.Linq.Enumerable.Skip{TSource}(IEnumerable{TSource}, Int32)"/>
 50      IAsyncEnumerable<T> Skip<T>( IAsyncEnumerable<T> enumerable, Int64 amount );
 51
 52
 53      /// <summary>
 54      /// This extension
 55      /// </summary>
 56      /// <typeparam name="T"></typeparam>
 57      /// <param name="enumerable"></param>
 58      /// <param name="predicate"></param>
 59      /// <returns></returns>
 60      /// <seealso cref="System.Linq.Enumerable.SkipWhile{TSource}(IEnumerable{TSource}, Func{TSource, Boolean})"/>
 61      IAsyncEnumerable<T> SkipWhile<T>( IAsyncEnumerable<T> enumerable, Func<T, Boolean> predicate );
 62
 63      /// <summary>
 64      ///
 65      /// </summary>
 66      /// <typeparam name="T"></typeparam>
 67      /// <param name="enumerable"></param>
 68      /// <param name="asyncPredicate"></param>
 69      /// <returns></returns>
 70      /// <seealso cref="System.Linq.Enumerable.SkipWhile{TSource}(IEnumerable{TSource}, Func{TSource, Boolean})"/>
 71      IAsyncEnumerable<T> SkipWhile<T>( IAsyncEnumerable<T> enumerable, Func<T, ValueTask<Boolean>> asyncPredicate );
 72   }
 73
 74}
 75
 76public static partial class E_AsyncEnumeration
 77{
 78
 79   /// <summary>
 80   /// This extension method will return <see cref="IAsyncEnumerable{T}"/> which will return at most given amount of ite
 81   /// </summary>
 82   /// <typeparam name="T">The type of items.</typeparam>
 83   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 84   /// <param name="amount">The maximum amount of items to return. If zero or less, will return empty enumerable.</param
 85   /// <returns><see cref="IAsyncEnumerable{T}"/> which will return at most given amount of items.</returns>
 86   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 87   /// <seealso cref="System.Linq.Enumerable.Skip{TSource}(IEnumerable{TSource}, Int32)"/>
 88   public static IAsyncEnumerable<T> Skip<T>( this IAsyncEnumerable<T> enumerable, Int32 amount )
 289      => ( enumerable.AsyncProvider ?? throw AsyncProviderUtilities.NoAsyncProviderException() ).Skip( enumerable, amoun
 90
 91   /// <summary>
 92   /// This extension method will return <see cref="IAsyncEnumerable{T}"/> which will return at most given amount of ite
 93   /// </summary>
 94   /// <typeparam name="T">The type of items.</typeparam>
 95   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 96   /// <param name="amount">The maximum amount of items to return. If zero or less, will return empty enumerable.</param
 97   /// <returns><see cref="IAsyncEnumerable{T}"/> which will return at most given amount of items.</returns>
 98   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 99   /// <seealso cref="System.Linq.Enumerable.Skip{TSource}(IEnumerable{TSource}, Int32)"/>
 100   public static IAsyncEnumerable<T> Skip<T>( this IAsyncEnumerable<T> enumerable, Int64 amount )
 2101      => ( enumerable.AsyncProvider ?? throw AsyncProviderUtilities.NoAsyncProviderException() ).Skip( enumerable, amoun
 102
 103   /// <summary>
 104   /// This extension
 105   /// </summary>
 106   /// <typeparam name="T"></typeparam>
 107   /// <param name="enumerable"></param>
 108   /// <param name="predicate"></param>
 109   /// <returns></returns>
 110   /// <seealso cref="System.Linq.Enumerable.SkipWhile{TSource}(IEnumerable{TSource}, Func{TSource, Boolean})"/>
 111   public static IAsyncEnumerable<T> SkipWhile<T>( this IAsyncEnumerable<T> enumerable, Func<T, Boolean> predicate )
 2112      => ( enumerable.AsyncProvider ?? throw AsyncProviderUtilities.NoAsyncProviderException() ).SkipWhile( enumerable, 
 113
 114   /// <summary>
 115   ///
 116   /// </summary>
 117   /// <typeparam name="T"></typeparam>
 118   /// <param name="enumerable"></param>
 119   /// <param name="asyncPredicate"></param>
 120   /// <returns></returns>
 121   /// <seealso cref="System.Linq.Enumerable.SkipWhile{TSource}(IEnumerable{TSource}, Func{TSource, Boolean})"/>
 122   public static IAsyncEnumerable<T> SkipWhile<T>( this IAsyncEnumerable<T> enumerable, Func<T, ValueTask<Boolean>> asyn
 2123      => ( enumerable.AsyncProvider ?? throw AsyncProviderUtilities.NoAsyncProviderException() ).SkipWhile( enumerable, 
 124
 125}

/repo-dir/contents/Source/Code/AsyncEnumeration.Abstractions/aLINQ/Take.cs

#LineLine coverage
 1/*
 2 * Copyright 2018 Stanislav Muhametsin. All rights Reserved.
 3 *
 4 * Licensed  under the  Apache License,  Version 2.0  (the "License");
 5 * you may not use  this file  except in  compliance with the License.
 6 * You may obtain a copy of the License at
 7 *
 8 *   http://www.apache.org/licenses/LICENSE-2.0
 9 *
 10 * Unless required by applicable law or agreed to in writing, software
 11 * distributed  under the  License is distributed on an "AS IS" BASIS,
 12 * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
 13 * implied.
 14 *
 15 * See the License for the specific language governing permissions and
 16 * limitations under the License.
 17 */
 18using AsyncEnumeration.Abstractions;
 19using System;
 20using System.Collections.Generic;
 21using System.Text;
 22using System.Threading;
 23using System.Threading.Tasks;
 24using UtilPack;
 25
 26namespace AsyncEnumeration.Abstractions
 27{
 28   public partial interface IAsyncProvider
 29   {
 30      /// <summary>
 31      /// This extension method will return <see cref="IAsyncEnumerable{T}"/> which will return at most given amount of 
 32      /// </summary>
 33      /// <typeparam name="T">The type of items.</typeparam>
 34      /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 35      /// <param name="amount">The maximum amount of items to return. If zero or less, will return empty enumerable.</pa
 36      /// <returns><see cref="IAsyncEnumerable{T}"/> which will return at most given amount of items.</returns>
 37      /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 38      /// <seealso cref="System.Linq.Enumerable.Take{TSource}(IEnumerable{TSource}, Int32)"/>
 39      IAsyncEnumerable<T> Take<T>( IAsyncEnumerable<T> enumerable, Int32 amount );
 40
 41      /// <summary>
 42      /// This extension method will return <see cref="IAsyncEnumerable{T}"/> which will return at most given amount of 
 43      /// </summary>
 44      /// <typeparam name="T">The type of items.</typeparam>
 45      /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 46      /// <param name="amount">The maximum amount of items to return. If zero or less, will return empty enumerable.</pa
 47      /// <returns><see cref="IAsyncEnumerable{T}"/> which will return at most given amount of items.</returns>
 48      /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 49      /// <seealso cref="System.Linq.Enumerable.Take{TSource}(IEnumerable{TSource}, Int32)"/>
 50      IAsyncEnumerable<T> Take<T>( IAsyncEnumerable<T> enumerable, Int64 amount );
 51
 52      /// <summary>
 53      /// This method returns new <see cref="IAsyncEnumerable{T}"/> that will include only the first elements of this <s
 54      /// </summary>
 55      /// <typeparam name="T">The type of elements being enumerated.</typeparam>
 56      /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 57      /// <param name="predicate">The synchronous callback to check whether element satisfies condition.</param>
 58      /// <returns><see cref="IAsyncEnumerable{T}"/> which will include only the first elements of this <see cref="IAsyn
 59      /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 60      /// <exception cref="ArgumentNullException">If <paramref name="predicate"/> is <c>null</c>.</exception>
 61      /// <seealso cref="System.Linq.Enumerable.TakeWhile{TSource}(IEnumerable{TSource}, Func{TSource, Boolean})"/>
 62      IAsyncEnumerable<T> TakeWhile<T>( IAsyncEnumerable<T> enumerable, Func<T, Boolean> predicate );
 63
 64      /// <summary>
 65      /// This method returns new <see cref="IAsyncEnumerable{T}"/> that will include only the first elements of this <s
 66      /// </summary>
 67      /// <typeparam name="T">The type of elements being enumerated.</typeparam>
 68      /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 69      /// <param name="asyncPredicate">The potentially asynchronous callback to check whether element satisfies conditio
 70      /// <returns><see cref="IAsyncEnumerable{T}"/> which will include only the first elements of this <see cref="IAsyn
 71      /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 72      /// <exception cref="ArgumentNullException">If <paramref name="asyncPredicate"/> is <c>null</c>.</exception>
 73      /// <seealso cref="System.Linq.Enumerable.TakeWhile{TSource}(IEnumerable{TSource}, Func{TSource, Boolean})"/>
 74      IAsyncEnumerable<T> TakeWhile<T>( IAsyncEnumerable<T> enumerable, Func<T, Task<Boolean>> asyncPredicate );
 75   }
 76
 77}
 78
 79
 80public static partial class E_AsyncEnumeration
 81{
 82
 83   /// <summary>
 84   /// This extension method will return <see cref="IAsyncEnumerable{T}"/> which will return at most given amount of ite
 85   /// </summary>
 86   /// <typeparam name="T">The type of items.</typeparam>
 87   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 88   /// <param name="amount">The maximum amount of items to return. If zero or less, will return empty enumerable.</param
 89   /// <returns><see cref="IAsyncEnumerable{T}"/> which will return at most given amount of items.</returns>
 90   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 91   /// <seealso cref="System.Linq.Enumerable.Take{TSource}(IEnumerable{TSource}, Int32)"/>
 92   public static IAsyncEnumerable<T> Take<T>( this IAsyncEnumerable<T> enumerable, Int32 amount )
 993      => ( enumerable.AsyncProvider ?? throw AsyncProviderUtilities.NoAsyncProviderException() ).Take( enumerable, amoun
 94
 95   /// <summary>
 96   /// This extension method will return <see cref="IAsyncEnumerable{T}"/> which will return at most given amount of ite
 97   /// </summary>
 98   /// <typeparam name="T">The type of items.</typeparam>
 99   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 100   /// <param name="amount">The maximum amount of items to return. If zero or less, will return empty enumerable.</param
 101   /// <returns><see cref="IAsyncEnumerable{T}"/> which will return at most given amount of items.</returns>
 102   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 103   /// <seealso cref="System.Linq.Enumerable.Take{TSource}(IEnumerable{TSource}, Int32)"/>
 104   public static IAsyncEnumerable<T> Take<T>( this IAsyncEnumerable<T> enumerable, Int64 amount )
 5105      => ( enumerable.AsyncProvider ?? throw AsyncProviderUtilities.NoAsyncProviderException() ).Take( enumerable, amoun
 106
 107   /// <summary>
 108   /// This method returns new <see cref="IAsyncEnumerable{T}"/> that will include only the first elements of this <see 
 109   /// </summary>
 110   /// <typeparam name="T">The type of elements being enumerated.</typeparam>
 111   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 112   /// <param name="predicate">The synchronous callback to check whether element satisfies condition.</param>
 113   /// <returns><see cref="IAsyncEnumerable{T}"/> which will include only the first elements of this <see cref="IAsyncEn
 114   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 115   /// <exception cref="ArgumentNullException">If <paramref name="predicate"/> is <c>null</c>.</exception>
 116   /// <seealso cref="System.Linq.Enumerable.TakeWhile{TSource}(IEnumerable{TSource}, Func{TSource, Boolean})"/>
 117   public static IAsyncEnumerable<T> TakeWhile<T>( this IAsyncEnumerable<T> enumerable, Func<T, Boolean> predicate )
 9118      => ( enumerable.AsyncProvider ?? throw AsyncProviderUtilities.NoAsyncProviderException() ).TakeWhile( enumerable, 
 119
 120   /// <summary>
 121   /// This method returns new <see cref="IAsyncEnumerable{T}"/> that will include only the first elements of this <see 
 122   /// </summary>
 123   /// <typeparam name="T">The type of elements being enumerated.</typeparam>
 124   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 125   /// <param name="asyncPredicate">The potentially asynchronous callback to check whether element satisfies condition.<
 126   /// <returns><see cref="IAsyncEnumerable{T}"/> which will include only the first elements of this <see cref="IAsyncEn
 127   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 128   /// <exception cref="ArgumentNullException">If <paramref name="asyncPredicate"/> is <c>null</c>.</exception>
 129   /// <seealso cref="System.Linq.Enumerable.TakeWhile{TSource}(IEnumerable{TSource}, Func{TSource, Boolean})"/>
 130   public static IAsyncEnumerable<T> TakeWhile<T>( this IAsyncEnumerable<T> enumerable, Func<T, Task<Boolean>> asyncPred
 6131      => ( enumerable.AsyncProvider ?? throw AsyncProviderUtilities.NoAsyncProviderException() ).TakeWhile( enumerable, 
 132
 133}

/repo-dir/contents/Source/Code/AsyncEnumeration.Abstractions/aLINQ/ToSynchronous.cs

#LineLine coverage
 1/*
 2 * Copyright 2017 Stanislav Muhametsin. All rights Reserved.
 3 *
 4 * Licensed  under the  Apache License,  Version 2.0  (the "License");
 5 * you may not use  this file  except in  compliance with the License.
 6 * You may obtain a copy of the License at
 7 *
 8 *   http://www.apache.org/licenses/LICENSE-2.0
 9 *
 10 * Unless required by applicable law or agreed to in writing, software
 11 * distributed  under the  License is distributed on an "AS IS" BASIS,
 12 * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
 13 * implied.
 14 *
 15 * See the License for the specific language governing permissions and
 16 * limitations under the License.
 17 */
 18using AsyncEnumeration.Abstractions;
 19using System;
 20using System.Collections.Generic;
 21using System.Text;
 22using System.Threading;
 23using System.Threading.Tasks;
 24using UtilPack;
 25
 26#if !NETSTANDARD1_0
 27using System.Collections.Concurrent;
 28#endif
 29
 30public static partial class E_AsyncEnumeration
 31{
 32   /// <summary>
 33   /// General-purpose extension method to add all items of this <see cref="IAsyncEnumerable{T}"/> to given collection.
 34   /// </summary>
 35   /// <typeparam name="T">The type of items being enumerated.</typeparam>
 36   /// <typeparam name="TCollection">The type of collection to add items to.</typeparam>
 37   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 38   /// <param name="collection">The collection to add to.</param>
 39   /// <param name="addItem">The callback to add the to the <paramref name="collection"/>.</param>
 40   /// <returns>Potentially asynchronously returns the amount of items encountered.</returns>
 41   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 42   /// <exception cref="ArgumentNullException">If <paramref name="addItem"/> is <c>null</c>.</exception>
 43   public static ValueTask<Int64> AddToCollectionAsync<T, TCollection>( this IAsyncEnumerable<T> enumerable, TCollection
 44   {
 4245      ArgumentValidator.ValidateNotNullReference( enumerable );
 4246      ArgumentValidator.ValidateNotNull( nameof( addItem ), addItem );
 47
 25148      return enumerable.EnumerateAsync( item => addItem( collection, item ) );
 49   }
 50
 51   /// <summary>
 52   /// General-purpose extension method to add all items of this <see cref="IAsyncEnumerable{T}"/> to given collection.
 53   /// </summary>
 54   /// <typeparam name="T">The type of items being enumerated.</typeparam>
 55   /// <typeparam name="TCollection">The type of collection to add items to.</typeparam>
 56   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 57   /// <param name="collection">The collection to add to.</param>
 58   /// <param name="addItem">The callback to add the to the <paramref name="collection"/>.</param>
 59   /// <returns>Potentially asynchronously returns the amount of items encountered.</returns>
 60   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 61   /// <exception cref="ArgumentNullException">If <paramref name="addItem"/> is <c>null</c>.</exception>
 62   public static ValueTask<Int64> AddToCollectionAsync<T, TCollection>( this IAsyncEnumerable<T> enumerable, TCollection
 63   {
 064      ArgumentValidator.ValidateNotNullReference( enumerable );
 065      ArgumentValidator.ValidateNotNull( nameof( addItem ), addItem );
 66
 067      return enumerable.EnumerateAsync( item => { return addItem( collection, item ); } );
 68   }
 69
 70   /// <summary>
 71   /// This extension method will enumerate this <see cref="IAsyncEnumerable{T}"/> into an array.
 72   /// </summary>
 73   /// <typeparam name="T">The type of items.</typeparam>
 74   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 75   /// <returns>An array of enumerated items.</returns>
 76   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 77   public static async Task<T[]> ToArrayAsync<T>( this IAsyncEnumerable<T> enumerable )
 4278      => ( await enumerable.ToListAsync() ).ToArray();
 79
 80   /// <summary>
 81   /// This extension method will enumerate this <see cref="IAsyncEnumerable{T}"/> into a <see cref="List{T}"/>.
 82   /// </summary>
 83   /// <typeparam name="T">The type of items.</typeparam>
 84   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 85   /// <returns>A <see cref="List{T}"/> of enumerated items.</returns>
 86   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 87   public static async Task<List<T>> ToListAsync<T>( this IAsyncEnumerable<T> enumerable )
 88   {
 4289      ArgumentValidator.ValidateNotNullReference( enumerable );
 4290      var retVal = new List<T>();
 25191      await enumerable.AddToCollectionAsync( retVal, ( list, item ) => list.Add( item ) );
 4292      return retVal;
 4293   }
 94
 95   /// <summary>
 96   /// This extension method will enumerate this <see cref="IAsyncEnumerable{T}"/> into a <see cref="IDictionary{TKey, T
 97   /// </summary>
 98   /// <typeparam name="T">The type of items being enumerated.</typeparam>
 99   /// <typeparam name="TKey">The type of dictionary keys.</typeparam>
 100   /// <typeparam name="TValue">The type of dictionary values.</typeparam>
 101   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 102   /// <param name="keySelector">The callback to create a dictionary key from enumerable item.</param>
 103   /// <param name="valueSelector">The callback to create a dictionary value from enumerable item.</param>
 104   /// <param name="equalityComparer">The optional <see cref="IEqualityComparer{T}"/> to use when creating dictionary.</
 105   /// <returns>Asynchronously returns a <see cref="IDictionary{TKey, TValue}"/> containing keys and values as returned 
 106   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 107   /// <exception cref="ArgumentNullException">If either of <paramref name="keySelector"/> or <paramref name="valueSelec
 108   public static async Task<IDictionary<TKey, TValue>> ToDictionaryAsync<T, TKey, TValue>(
 109      this IAsyncEnumerable<T> enumerable,
 110      Func<T, TKey> keySelector,
 111      Func<T, TValue> valueSelector,
 112      IEqualityComparer<TKey> equalityComparer = null
 113      )
 114   {
 0115      ArgumentValidator.ValidateNotNullReference( enumerable );
 0116      ArgumentValidator.ValidateNotNull( nameof( keySelector ), keySelector );
 0117      ArgumentValidator.ValidateNotNull( nameof( valueSelector ), valueSelector );
 118
 0119      var retVal = new Dictionary<TKey, TValue>( equalityComparer );
 0120      await enumerable.AddToCollectionAsync( retVal, ( dictionary, item ) => dictionary.Add( keySelector( item ), valueS
 0121      return retVal;
 0122   }
 123
 124   /// <summary>
 125   /// This extension method will enumerate this <see cref="IAsyncEnumerable{T}"/> into a <see cref="IDictionary{TKey, T
 126   /// </summary>
 127   /// <typeparam name="T">The type of items being enumerated.</typeparam>
 128   /// <typeparam name="TKey">The type of dictionary keys.</typeparam>
 129   /// <typeparam name="TValue">The type of dictionary values.</typeparam>
 130   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 131   /// <param name="keySelector">The callback to potentially asynchronously create a dictionary key from enumerable item
 132   /// <param name="valueSelector">The callback to potentially asynchronously create a dictionary value from enumerable 
 133   /// <param name="equalityComparer">The optional <see cref="IEqualityComparer{T}"/> to use when creating dictionary.</
 134   /// <returns>Asynchronously returns a <see cref="IDictionary{TKey, TValue}"/> containing keys and values as returned 
 135   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 136   /// <exception cref="ArgumentNullException">If either of <paramref name="keySelector"/> or <paramref name="valueSelec
 137   public static async Task<IDictionary<TKey, TValue>> ToDictionaryAsync<T, TKey, TValue>(
 138      this IAsyncEnumerable<T> enumerable,
 139      Func<T, ValueTask<TKey>> keySelector,
 140      Func<T, ValueTask<TValue>> valueSelector,
 141      IEqualityComparer<TKey> equalityComparer = null
 142      )
 143   {
 0144      ArgumentValidator.ValidateNotNullReference( enumerable );
 0145      ArgumentValidator.ValidateNotNull( nameof( keySelector ), keySelector );
 0146      ArgumentValidator.ValidateNotNull( nameof( valueSelector ), valueSelector );
 147
 0148      var retVal = new Dictionary<TKey, TValue>( equalityComparer );
 0149      await enumerable.AddToCollectionAsync( retVal, async ( dictionary, item ) => dictionary.Add( await keySelector( it
 0150      return retVal;
 0151   }
 152
 153   /// <summary>
 154   /// General-purpose extension method to add all items of this <see cref="IAsyncEnumerable{T}"/> to given concurrent c
 155   /// </summary>
 156   /// <typeparam name="T">The type of items being enumerated.</typeparam>
 157   /// <typeparam name="TCollection">The type of collection to add items to.</typeparam>
 158   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 159   /// <param name="collection">The collection to add to.</param>
 160   /// <param name="addItem">The callback to add the to the <paramref name="collection"/>. May be executed concurrently.
 161   /// <returns>Potentially asynchronously returns the amount of items encountered.</returns>
 162   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 163   /// <exception cref="ArgumentNullException">If <paramref name="addItem"/> is <c>null</c>.</exception>
 164   public static ValueTask<Int64> AddToConcurrentCollectionAsync<T, TCollection>( this IAsyncEnumerable<T> enumerable, T
 165   {
 0166      ArgumentValidator.ValidateNotNullReference( enumerable );
 0167      ArgumentValidator.ValidateNotNull( nameof( addItem ), addItem );
 168
 0169      return enumerable.EnumerateAsync( item => addItem( collection, item ) );
 170   }
 171
 172   /// <summary>
 173   /// General-purpose extension method to add all items of this <see cref="IAsyncEnumerable{T}"/> to given concurrent c
 174   /// </summary>
 175   /// <typeparam name="T">The type of items being enumerated.</typeparam>
 176   /// <typeparam name="TCollection">The type of collection to add items to.</typeparam>
 177   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 178   /// <param name="collection">The collection to add to.</param>
 179   /// <param name="addItem">The callback to asynchronously add the to the <paramref name="collection"/>. May be execute
 180   /// <returns>Potentially asynchronously returns the amount of items encountered.</returns>
 181   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 182   /// <exception cref="ArgumentNullException">If <paramref name="addItem"/> is <c>null</c>.</exception>
 183   public static ValueTask<Int64> AddToConcurrentCollectionAsync<T, TCollection>( this IAsyncEnumerable<T> enumerable, T
 184   {
 0185      ArgumentValidator.ValidateNotNullReference( enumerable );
 0186      ArgumentValidator.ValidateNotNull( nameof( addItem ), addItem );
 187
 0188      return enumerable.EnumerateAsync( item => { return addItem( collection, item ); } );
 189   }
 190
 191#if !NETSTANDARD1_0
 192
 193   /// <summary>
 194   /// This extension method creates a new <see cref="ConcurrentBag{T}"/> and possibly concurrently enumerates this <see
 195   /// </summary>
 196   /// <typeparam name="T">The type of items being enumerated.</typeparam>
 197   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 198   /// <returns>A new <see cref="ConcurrentBag{T}"/> holding all items encountered while enumerating this <see cref="IAs
 199   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 200   public static async Task<ConcurrentBag<T>> ToConcurrentBagAsync<T>( this IAsyncEnumerable<T> enumerable )
 201   {
 0202      var retVal = new ConcurrentBag<T>();
 0203      await enumerable.AddToConcurrentCollectionAsync( retVal, ( bag, item ) => bag.Add( item ) );
 0204      return retVal;
 0205   }
 206
 207   /// <summary>
 208   /// This extension method creates a new <see cref="ConcurrentQueue{T}"/> and possibly concurrently enumerates this <s
 209   /// </summary>
 210   /// <typeparam name="T">The type of items being enumerated.</typeparam>
 211   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 212   /// <returns>A new <see cref="ConcurrentQueue{T}"/> holding all items encountered while enumerating this <see cref="I
 213   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 214   public static async Task<ConcurrentQueue<T>> ToConcurrentQueueAsync<T>( this IAsyncEnumerable<T> enumerable )
 215   {
 0216      var retVal = new ConcurrentQueue<T>();
 0217      await enumerable.AddToConcurrentCollectionAsync( retVal, ( queue, item ) => queue.Enqueue( item ) );
 0218      return retVal;
 0219   }
 220
 221   /// <summary>
 222   /// This extension method creates a new <see cref="ConcurrentStack{T}"/> and possibly concurrently enumerates this <s
 223   /// </summary>
 224   /// <typeparam name="T">The type of items being enumerated.</typeparam>
 225   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 226   /// <returns>A new <see cref="ConcurrentStack{T}"/> holding all items encountered while enumerating this <see cref="I
 227   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 228   public static async Task<ConcurrentStack<T>> ToConcurrentStackAsync<T>( this IAsyncEnumerable<T> enumerable )
 229   {
 0230      var retVal = new ConcurrentStack<T>();
 0231      await enumerable.AddToConcurrentCollectionAsync( retVal, ( stack, item ) => stack.Push( item ) );
 0232      return retVal;
 0233   }
 234
 235   /// <summary>
 236   /// This extension method creates a new <see cref="ConcurrentBag{T}"/> and possibly concurrently enumerates this <see
 237   /// </summary>
 238   /// <typeparam name="T">The type of items being enumerated.</typeparam>
 239   /// <typeparam name="U">The type of items added to <see cref="ConcurrentBag{T}"/>.</typeparam>
 240   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 241   /// <param name="selector">The callback to asynchronously select an object to be added to <see cref="ConcurrentBag{T}
 242   /// <returns>A new <see cref="ConcurrentBag{T}"/> holding all transformed items encountered while enumerating this <s
 243   /// <remarks>
 244   /// <para>
 245   /// The motivation for this method is that often the items enumerated by <see cref="IAsyncEnumerable{T}"/> are "incom
 246   /// Using <see cref="Select{T, U}(IAsyncEnumerable{T}, Func{T, ValueTask{U}})"/> method will force the <see cref="IAs
 247   /// Therefore, using this method directly it is possible to enumerate this <see cref="IAsyncEnumerable{T}"/> possibly
 248   /// </para>
 249   /// </remarks>
 250   public static async Task<ConcurrentBag<U>> ToConcurrentBagAsync<T, U>( this IAsyncEnumerable<T> enumerable, Func<T, T
 251   {
 0252      ArgumentValidator.ValidateNotNull( nameof( selector ), selector );
 0253      var retVal = new ConcurrentBag<U>();
 0254      await enumerable.AddToConcurrentCollectionAsync( retVal, async ( bag, item ) => bag.Add( await selector( item ) ) 
 0255      return retVal;
 0256   }
 257
 258   /// <summary>
 259   /// This extension method creates a new <see cref="ConcurrentQueue{T}"/> and possibly concurrently enumerates this <s
 260   /// </summary>
 261   /// <typeparam name="T">The type of items being enumerated.</typeparam>
 262   /// <typeparam name="U">The type of items added to <see cref="ConcurrentQueue{T}"/>.</typeparam>
 263   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 264   /// <param name="selector">The callback to asynchronously select an object to be added to <see cref="ConcurrentQueue{
 265   /// <returns>A new <see cref="ConcurrentQueue{T}"/> holding all transformed items encountered while enumerating this 
 266   /// <remarks>
 267   /// <para>
 268   /// The motivation for this method is that often the items enumerated by <see cref="IAsyncEnumerable{T}"/> are "incom
 269   /// Using <see cref="Select{T, U}(IAsyncEnumerable{T}, Func{T, ValueTask{U}})"/> method will force the <see cref="IAs
 270   /// Therefore, using this method directly it is possible to enumerate this <see cref="IAsyncEnumerable{T}"/> possibly
 271   /// </para>
 272   /// </remarks>
 273   public static async Task<ConcurrentQueue<U>> ToConcurrentQueueAsync<T, U>( this IAsyncEnumerable<T> enumerable, Func<
 274   {
 0275      ArgumentValidator.ValidateNotNull( nameof( selector ), selector );
 0276      var retVal = new ConcurrentQueue<U>();
 0277      await enumerable.AddToConcurrentCollectionAsync( retVal, async ( queue, item ) => queue.Enqueue( await selector( i
 0278      return retVal;
 0279   }
 280
 281   /// <summary>
 282   /// This extension method creates a new <see cref="ConcurrentStack{T}"/> and possibly concurrently enumerates this <s
 283   /// </summary>
 284   /// <typeparam name="T">The type of items being enumerated.</typeparam>
 285   /// <typeparam name="U">The type of items added to <see cref="ConcurrentStack{T}"/>.</typeparam>
 286   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 287   /// <param name="selector">The callback to asynchronously select an object to be added to <see cref="ConcurrentStack{
 288   /// <returns>A new <see cref="ConcurrentStack{T}"/> holding all transformed items encountered while enumerating this 
 289   /// <remarks>
 290   /// <para>
 291   /// The motivation for this method is that often the items enumerated by <see cref="IAsyncEnumerable{T}"/> are "incom
 292   /// Using <see cref="Select{T, U}(IAsyncEnumerable{T}, Func{T, ValueTask{U}})"/> method will force the <see cref="IAs
 293   /// Therefore, using this method directly it is possible to enumerate this <see cref="IAsyncEnumerable{T}"/> possibly
 294   /// </para>
 295   /// </remarks>
 296   public static async Task<ConcurrentStack<U>> ToConcurrentStackAsync<T, U>( this IAsyncEnumerable<T> enumerable, Func<
 297   {
 0298      ArgumentValidator.ValidateNotNull( nameof( selector ), selector );
 0299      var retVal = new ConcurrentStack<U>();
 0300      await enumerable.AddToConcurrentCollectionAsync( retVal, async ( stack, item ) => stack.Push( await selector( item
 0301      return retVal;
 0302   }
 303
 304   /// <summary>
 305   /// This extension method will possibly concurrently enumerate this <see cref="IAsyncEnumerable{T}"/> into a <see cre
 306   /// </summary>
 307   /// <typeparam name="T">The type of items being enumerated.</typeparam>
 308   /// <typeparam name="TKey">The type of dictionary keys.</typeparam>
 309   /// <typeparam name="TValue">The type of dictionary values.</typeparam>
 310   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 311   /// <param name="keySelector">The callback to create a dictionary key from enumerable item.</param>
 312   /// <param name="valueSelector">The callback to create a dictionary value from enumerable item.</param>
 313   /// <param name="equalityComparer">The optional <see cref="IEqualityComparer{T}"/> to use when creating dictionary.</
 314   /// <returns>Asynchronously returns a <see cref="IDictionary{TKey, TValue}"/> containing keys and values as returned 
 315   /// <remarks>
 316   /// <para>
 317   /// TODO currently this will not throw if there are duplicate keys, unlike <see cref="ToDictionaryAsync{T, TKey, TVal
 318   /// The behaviour needs to be unified/parametrized at some point.
 319   /// </para>
 320   /// </remarks>
 321   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 322   /// <exception cref="ArgumentNullException">If either of <paramref name="keySelector"/> or <paramref name="valueSelec
 323   public static async Task<ConcurrentDictionary<TKey, TValue>> ToConcurrentDictionaryAsync<T, TKey, TValue>(
 324      this IAsyncEnumerable<T> enumerable,
 325      Func<T, TKey> keySelector,
 326      Func<T, TValue> valueSelector,
 327      IEqualityComparer<TKey> equalityComparer = null
 328      )
 329   {
 0330      ArgumentValidator.ValidateNotNullReference( enumerable );
 0331      ArgumentValidator.ValidateNotNull( nameof( keySelector ), keySelector );
 0332      ArgumentValidator.ValidateNotNull( nameof( valueSelector ), valueSelector );
 333
 334      // Normal Dictionary<TKey, TValue> constructor accepts null as equality comparer, but ConcurrentDictionary throws.
 0335      var retVal = new ConcurrentDictionary<TKey, TValue>( equalityComparer ?? EqualityComparer<TKey>.Default );
 0336      await enumerable.AddToConcurrentCollectionAsync( retVal, ( dictionary, item ) => dictionary.TryAdd( keySelector( i
 0337      return retVal;
 0338   }
 339
 340   /// <summary>
 341   /// This extension method will possibly concurrently enumerate this <see cref="IAsyncEnumerable{T}"/> into a <see cre
 342   /// </summary>
 343   /// <typeparam name="T">The type of items being enumerated.</typeparam>
 344   /// <typeparam name="TKey">The type of dictionary keys.</typeparam>
 345   /// <typeparam name="TValue">The type of dictionary values.</typeparam>
 346   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 347   /// <param name="keySelector">The callback to potentially asynchronously create a dictionary key from enumerable item
 348   /// <param name="valueSelector">The callback to potentially asynchronously create a dictionary value from enumerable 
 349   /// <param name="equalityComparer">The optional <see cref="IEqualityComparer{T}"/> to use when creating dictionary.</
 350   /// <returns>Asynchronously returns a <see cref="IDictionary{TKey, TValue}"/> containing keys and values as returned 
 351   /// <remarks>
 352   /// <para>
 353   /// TODO currently this will not throw if there are duplicate keys, unlike <see cref="ToDictionaryAsync{T, TKey, TVal
 354   /// The behaviour needs to be unified/parametrized at some point.
 355   /// </para>
 356   /// </remarks>
 357   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 358   /// <exception cref="ArgumentNullException">If either of <paramref name="keySelector"/> or <paramref name="valueSelec
 359   public static async Task<ConcurrentDictionary<TKey, TValue>> ToConcurrentDictionaryAsync<T, TKey, TValue>(
 360      this IAsyncEnumerable<T> enumerable,
 361      Func<T, ValueTask<TKey>> keySelector,
 362      Func<T, ValueTask<TValue>> valueSelector,
 363      IEqualityComparer<TKey> equalityComparer = null
 364      )
 365   {
 0366      ArgumentValidator.ValidateNotNullReference( enumerable );
 0367      ArgumentValidator.ValidateNotNull( nameof( keySelector ), keySelector );
 0368      ArgumentValidator.ValidateNotNull( nameof( valueSelector ), valueSelector );
 369
 370      // Normal Dictionary<TKey, TValue> constructor accepts null as equality comparer, but ConcurrentDictionary throws.
 0371      var retVal = new ConcurrentDictionary<TKey, TValue>( equalityComparer ?? EqualityComparer<TKey>.Default );
 0372      await enumerable.AddToConcurrentCollectionAsync( retVal, async ( dictionary, item ) => dictionary.TryAdd( await ke
 0373      return retVal;
 0374   }
 375
 376#endif
 377}

/repo-dir/contents/Source/Code/AsyncEnumeration.Abstractions/aLINQ/Where.cs

#LineLine coverage
 1/*
 2 * Copyright 2017 Stanislav Muhametsin. All rights Reserved.
 3 *
 4 * Licensed  under the  Apache License,  Version 2.0  (the "License");
 5 * you may not use  this file  except in  compliance with the License.
 6 * You may obtain a copy of the License at
 7 *
 8 *   http://www.apache.org/licenses/LICENSE-2.0
 9 *
 10 * Unless required by applicable law or agreed to in writing, software
 11 * distributed  under the  License is distributed on an "AS IS" BASIS,
 12 * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
 13 * implied.
 14 *
 15 * See the License for the specific language governing permissions and
 16 * limitations under the License.
 17 */
 18using AsyncEnumeration.Abstractions;
 19using System;
 20using System.Collections.Generic;
 21using System.Text;
 22using System.Threading;
 23using System.Threading.Tasks;
 24using UtilPack;
 25
 26namespace AsyncEnumeration.Abstractions
 27{
 28   public partial interface IAsyncProvider
 29   {
 30      /// <summary>
 31      /// This extension method will return <see cref="IAsyncEnumerable{T}"/> which will filter items based on given pre
 32      /// </summary>
 33      /// <typeparam name="T">The type of items.</typeparam>
 34      /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 35      /// <param name="predicate">The callback which will filter the results. By returning <c>true</c>, the result will 
 36      /// <returns><see cref="IAsyncEnumerable{T}"/> which will filter items based on given predicate callback.</returns
 37      /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 38      /// <exception cref="ArgumentNullException">If <paramref name="predicate"/> is <c>null</c>.</exception>
 39      /// <seealso cref="System.Linq.Enumerable.Where{TSource}(IEnumerable{TSource}, Func{TSource, Boolean})"/>
 40      IAsyncEnumerable<T> Where<T>( IAsyncEnumerable<T> enumerable, Func<T, Boolean> predicate );
 41
 42      /// <summary>
 43      /// This extension method will return <see cref="IAsyncEnumerable{T}"/> which will filter items based on given asy
 44      /// </summary>
 45      /// <typeparam name="T">The type of items.</typeparam>
 46      /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 47      /// <param name="asyncPredicate">The callback which will asynchronously filter the results. By returning <c>true</
 48      /// <returns><see cref="IAsyncEnumerable{T}"/> which will filter items based on given predicate callback.</returns
 49      /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 50      /// <exception cref="ArgumentNullException">If <paramref name="asyncPredicate"/> is <c>null</c>.</exception>
 51      /// <seealso cref="System.Linq.Enumerable.Where{TSource}(IEnumerable{TSource}, Func{TSource, Boolean})"/>
 52      IAsyncEnumerable<T> Where<T>( IAsyncEnumerable<T> enumerable, Func<T, Task<Boolean>> asyncPredicate );
 53   }
 54
 55
 56}
 57
 58
 59public static partial class E_AsyncEnumeration
 60{
 61
 62   /// <summary>
 63   /// This extension method will return <see cref="IAsyncEnumerable{T}"/> which will filter items based on given predic
 64   /// </summary>
 65   /// <typeparam name="T">The type of items.</typeparam>
 66   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 67   /// <param name="predicate">The callback which will filter the results. By returning <c>true</c>, the result will be 
 68   /// <returns><see cref="IAsyncEnumerable{T}"/> which will filter items based on given predicate callback.</returns>
 69   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 70   /// <exception cref="ArgumentNullException">If <paramref name="predicate"/> is <c>null</c>.</exception>
 71   /// <seealso cref="System.Linq.Enumerable.Where{TSource}(IEnumerable{TSource}, Func{TSource, Boolean})"/>
 72   public static IAsyncEnumerable<T> Where<T>( this IAsyncEnumerable<T> enumerable, Func<T, Boolean> predicate )
 373      => ( enumerable.AsyncProvider ?? throw AsyncProviderUtilities.NoAsyncProviderException() ).Where( enumerable, pred
 74
 75   /// <summary>
 76   /// This extension method will return <see cref="IAsyncEnumerable{T}"/> which will filter items based on given asynch
 77   /// </summary>
 78   /// <typeparam name="T">The type of items.</typeparam>
 79   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 80   /// <param name="asyncPredicate">The callback which will asynchronously filter the results. By returning <c>true</c>,
 81   /// <returns><see cref="IAsyncEnumerable{T}"/> which will filter items based on given predicate callback.</returns>
 82   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 83   /// <exception cref="ArgumentNullException">If <paramref name="asyncPredicate"/> is <c>null</c>.</exception>
 84   /// <seealso cref="System.Linq.Enumerable.Where{TSource}(IEnumerable{TSource}, Func{TSource, Boolean})"/>
 85   public static IAsyncEnumerable<T> Where<T>( this IAsyncEnumerable<T> enumerable, Func<T, Task<Boolean>> asyncPredicat
 286      => ( enumerable.AsyncProvider ?? throw AsyncProviderUtilities.NoAsyncProviderException() ).Where( enumerable, asyn
 87}

/repo-dir/contents/Source/Code/AsyncEnumeration.Abstractions/Enumeration.cs

#LineLine coverage
 1/*
 2 * Copyright 2017 Stanislav Muhametsin. All rights Reserved.
 3 *
 4 * Licensed  under the  Apache License,  Version 2.0  (the "License");
 5 * you may not use  this file  except in  compliance with the License.
 6 * You may obtain a copy of the License at
 7 *
 8 *   http://www.apache.org/licenses/LICENSE-2.0
 9 *
 10 * Unless required by applicable law or agreed to in writing, software
 11 * distributed  under the  License is distributed on an "AS IS" BASIS,
 12 * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
 13 * implied.
 14 *
 15 * See the License for the specific language governing permissions and
 16 * limitations under the License.
 17 */
 18using AsyncEnumeration.Abstractions;
 19using System;
 20using System.Collections.Generic;
 21using System.Linq;
 22using System.Text;
 23using System.Threading;
 24using System.Threading.Tasks;
 25using UtilPack;
 26
 27namespace AsyncEnumeration.Abstractions
 28{
 29   public partial interface IAsyncProvider
 30   {
 31      ///// <summary>
 32      ///// This is helper method to sequentially enumerate a <see cref="IAsyncEnumerable{T}"/> and properly dispose it 
 33      ///// </summary>
 34      ///// <typeparam name="T">The type of the items being enumerated.</typeparam>
 35      ///// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 36      ///// <returns>A task which will have enumerated the <see cref="IAsyncEnumerable{T}"/> on completion. The return v
 37      ///// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exceptio
 38      ///// <exception cref="OverflowException">If there are more than <see cref="Int64.MaxValue"/> amount of items enco
 39      ///// <remarks>
 40      ///// Sequential enumeration means that the next invocation of <see cref="IAsyncEnumerator{T}.WaitForNextAsync"/> 
 41      ///// </remarks>
 42      //ValueTask<Int64> EnumerateAsync<T>( IAsyncEnumerable<T> enumerable );
 43
 44      ///// <summary>
 45      ///// This is helper method to sequentially enumerate a <see cref="IAsyncEnumerator{T}"/> and properly dispose it 
 46      ///// </summary>
 47      ///// <typeparam name="T">The type of the items being enumerated.</typeparam>
 48      ///// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 49      ///// <param name="action">The callback to invoke for each item. May be <c>null</c>.</param>
 50      ///// <returns>A task which will have enumerated the <see cref="IAsyncEnumerable{T}"/> on completion. The return v
 51      ///// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exceptio
 52      ///// <exception cref="OverflowException">If there are more than <see cref="Int64.MaxValue"/> amount of items enco
 53      ///// <remarks>
 54      ///// Sequential enumeration means that the next invocation of <see cref="IAsyncEnumerator{T}.WaitForNextAsync"/> 
 55      ///// </remarks>
 56      //ValueTask<Int64> EnumerateAsync<T>( IAsyncEnumerable<T> enumerable, Action<T> action );
 57
 58      ///// <summary>
 59      ///// This is helper method to sequentially enumerate a <see cref="IAsyncEnumerable{T}"/> and properly dispose it 
 60      ///// For each item, a task from given callback is awaited for, if the callback is not <c>null</c>.
 61      ///// </summary>
 62      ///// <typeparam name="T">The type of the items being enumerated.</typeparam>
 63      ///// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 64      ///// <param name="asyncAction">The callback to invoke for each item. May be <c>null</c>, and may also return <c>n
 65      ///// <returns>A task which will have enumerated the <see cref="IAsyncEnumerable{T}"/> on completion. The return v
 66      ///// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exceptio
 67      ///// <exception cref="OverflowException">If there are more than <see cref="Int64.MaxValue"/> amount of items enco
 68      ///// <remarks>
 69      ///// Sequential enumeration means that the next invocation of <see cref="IAsyncEnumerator{T}.WaitForNextAsync"/> 
 70      ///// </remarks>
 71      //ValueTask<Int64> EnumerateAsync<T>( IAsyncEnumerable<T> enumerable, Func<T, Task> asyncAction );
 72   }
 73}
 74
 75/// <summary>
 76/// This class contains extension methods for UtilPack types.
 77/// </summary>
 78public static partial class E_AsyncEnumeration
 79{
 80   /// <summary>
 81   /// This is helper method to sequentially enumerate a <see cref="IAsyncEnumerator{T}"/> and properly dispose it in ca
 82   /// </summary>
 83   /// <typeparam name="T">The type of the items being enumerated.</typeparam>
 84   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 85   /// <param name="action">The callback to invoke for each item. May be <c>null</c>.</param>
 86   /// <returns>A task which will have enumerated the <see cref="IAsyncEnumerable{T}"/> on completion. The return value 
 87   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 88   /// <exception cref="OverflowException">If there are more than <see cref="Int64.MaxValue"/> amount of items encounter
 89   /// <remarks>
 90   /// Sequential enumeration means that the next invocation of <see cref="IAsyncEnumerator{T}.WaitForNextAsync"/> will 
 91   /// </remarks>
 92   public static async ValueTask<Int64> EnumerateAsync<T>( this IAsyncEnumerable<T> enumerable, Action<T> action )
 93   {
 5794      var enumerator = enumerable.GetAsyncEnumerator();
 95      try
 96      {
 5797         var retVal = 0L;
 13298         while ( await enumerator.WaitForNextAsync() )
 99         {
 100            Boolean success;
 101            do
 102            {
 321103               var item = enumerator.TryGetNext( out success );
 321104               if ( success )
 105               {
 246106                  ++retVal;
 246107                  action?.Invoke( item );
 108               }
 321109            } while ( success );
 110         }
 57111         return retVal;
 112      }
 113      finally
 114      {
 57115         await enumerator.DisposeAsync();
 116      }
 57117   }
 118
 119   /// <summary>
 120   /// This is helper method to sequentially enumerate a <see cref="IAsyncEnumerable{T}"/> and properly dispose it in ca
 121   /// For each item, a task from given callback is awaited for, if the callback is not <c>null</c>.
 122   /// </summary>
 123   /// <typeparam name="T">The type of the items being enumerated.</typeparam>
 124   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 125   /// <param name="asyncAction">The callback to invoke for each item. May be <c>null</c>, and may also return <c>null</
 126   /// <returns>A task which will have enumerated the <see cref="IAsyncEnumerable{T}"/> on completion. The return value 
 127   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 128   /// <exception cref="OverflowException">If there are more than <see cref="Int64.MaxValue"/> amount of items encounter
 129   /// <remarks>
 130   /// Sequential enumeration means that the next invocation of <see cref="IAsyncEnumerator{T}.WaitForNextAsync"/> will 
 131   /// </remarks>
 132   public static async ValueTask<Int64> EnumerateAsync<T>( this IAsyncEnumerable<T> enumerable, Func<T, Task> asyncActio
 133   {
 4134      var enumerator = enumerable.GetAsyncEnumerator();
 135      try
 136      {
 4137         var retVal = 0L;
 17138         while ( await enumerator.WaitForNextAsync() )
 139         {
 140            Boolean success;
 141            do
 142            {
 48143               var item = enumerator.TryGetNext( out success );
 48144               if ( success )
 145               {
 35146                  ++retVal;
 35147                  var task = asyncAction?.Invoke( item );
 35148                  if ( task != null )
 149                  {
 35150                     await task;
 151                  }
 152               }
 48153            } while ( success );
 154         }
 4155         return retVal;
 156      }
 157      finally
 158      {
 4159         await enumerator.DisposeAsync();
 160      }
 4161   }
 162
 163   /// <summary>
 164   /// This is helper method to sequentially enumerate a <see cref="IAsyncEnumerable{T}"/> and properly dispose it in ca
 165   /// </summary>
 166   /// <typeparam name="T">The type of the items being enumerated.</typeparam>
 167   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 168   /// <param name="callback">The synchronous callback invoked for each element of this <see cref="IAsyncEnumerable{T}"/
 169   /// <returns>A task which will have enumerated the <see cref="IAsyncEnumerable{T}"/> on completion. The return value 
 170   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 171   /// <exception cref="OverflowException">If there are more than <see cref="Int64.MaxValue"/> amount of items encounter
 172   /// <remarks>
 173   /// Sequential enumeration means that the next invocation of <see cref="IAsyncEnumerator{T}.WaitForNextAsync"/> will 
 174   /// </remarks>
 175   public static ValueTask<Int64> EnumerateAsync<T>( this IAsyncEnumerable<T> enumerable, Func<T, Boolean> callback )
 7176      => enumerable.TakeWhile( callback ).EnumerateAsync();
 177
 178
 179   /// <summary>
 180   /// This is helper method to sequentially enumerate a <see cref="IAsyncEnumerable{T}"/> and properly dispose it in ca
 181   /// </summary>
 182   /// <typeparam name="T">The type of the items being enumerated.</typeparam>
 183   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 184   /// <param name="asyncCallback">The potentially asynchronous callback invoked for each element of this <see cref="IAs
 185   /// <returns>A task which will have enumerated the <see cref="IAsyncEnumerable{T}"/> on completion. The return value 
 186   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 187   /// <exception cref="OverflowException">If there are more than <see cref="Int64.MaxValue"/> amount of items encounter
 188   /// <remarks>
 189   /// Sequential enumeration means that the next invocation of <see cref="IAsyncEnumerator{T}.WaitForNextAsync"/> will 
 190   /// </remarks>
 191   public static ValueTask<Int64> EnumerateAsync<T>( this IAsyncEnumerable<T> enumerable, Func<T, Task<Boolean>> asyncCa
 4192      => enumerable.TakeWhile( asyncCallback ).EnumerateAsync();
 193
 194   /// <summary>
 195   /// This is helper method to sequentially enumerate a <see cref="IAsyncEnumerable{T}"/> and properly dispose it in ca
 196   /// </summary>
 197   /// <typeparam name="T">The type of the items being enumerated.</typeparam>
 198   /// <param name="enumerable">This <see cref="IAsyncEnumerable{T}"/>.</param>
 199   /// <returns>A task which will have enumerated the <see cref="IAsyncEnumerable{T}"/> on completion. The return value 
 200   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 201   /// <exception cref="OverflowException">If there are more than <see cref="Int64.MaxValue"/> amount of items encounter
 202   /// <remarks>
 203   /// Sequential enumeration means that the next invocation of <see cref="IAsyncEnumerator{T}.WaitForNextAsync"/> will 
 204   /// </remarks>
 205   public static ValueTask<Int64> EnumerateAsync<T>( this IAsyncEnumerable<T> enumerable )
 206   {
 11207      return EnumerateAsync( enumerable, null as Action<T> );
 208   }
 209
 210   //private static async ValueTask<Int64> EnumerateSequentiallyAsync<T>( this IAsyncEnumerator<T> enumerator, Func<T, B
 211   //{
 212   //   try
 213   //   {
 214   //      var retVal = 0L;
 215   //      var shouldContinue = true;
 216   //      while ( shouldContinue && await enumerator.WaitForNextAsync() )
 217   //      {
 218   //         Boolean success;
 219   //         do
 220   //         {
 221   //            var item = enumerator.TryGetNext( out success );
 222   //            if ( success )
 223   //            {
 224   //               ++retVal;
 225   //               if ( action != null )
 226   //               {
 227   //                  shouldContinue = action( item );
 228   //               }
 229   //            }
 230   //         } while ( shouldContinue && success );
 231   //      }
 232   //      return retVal;
 233   //   }
 234   //   finally
 235   //   {
 236   //      await enumerator.DisposeAsync();
 237   //   }
 238   //}
 239
 240   //private static async ValueTask<Int64> EnumerateSequentiallyAsync<T>( this IAsyncEnumerator<T> enumerator, Func<T, T
 241   //{
 242   //   try
 243   //   {
 244   //      var retVal = 0L;
 245   //      var shouldContinue = true;
 246   //      while ( shouldContinue && await enumerator.WaitForNextAsync() )
 247   //      {
 248   //         Boolean success;
 249   //         do
 250   //         {
 251   //            var item = enumerator.TryGetNext( out success );
 252   //            if ( success )
 253   //            {
 254   //               ++retVal;
 255   //               var task = asyncAction?.Invoke( item );
 256   //               if ( task != null )
 257   //               {
 258   //                  shouldContinue = await task;
 259   //               }
 260   //            }
 261   //         } while ( shouldContinue && success );
 262   //      }
 263   //      return retVal;
 264   //   }
 265   //   finally
 266   //   {
 267   //      await enumerator.DisposeAsync();
 268   //   }
 269   //}
 270
 271}

Methods/Properties

AggregateAsync(System.Collections.Generic.IAsyncEnumerable`1<T>,System.Func`3<T,T,T>)
AggregateAsync(System.Collections.Generic.IAsyncEnumerable`1<T>,System.Func`3<T,T,System.Threading.Tasks.ValueTask`1<T>>)
AggregateAsync(System.Collections.Generic.IAsyncEnumerable`1<T>,System.Func`3<TResult,T,TResult>,TResult)
AggregateAsync(System.Collections.Generic.IAsyncEnumerable`1<T>,System.Func`3<TResult,T,System.Threading.Tasks.ValueTask`1<TResult>>,TResult)
AnyAsync(System.Collections.Generic.IAsyncEnumerable`1<T>)
AnyAsync(System.Collections.Generic.IAsyncEnumerable`1<T>,System.Func`2<T,System.Boolean>)
AnyAsync(System.Collections.Generic.IAsyncEnumerable`1<T>,System.Func`2<T,System.Threading.Tasks.ValueTask`1<System.Boolean>>)
AllAsync(System.Collections.Generic.IAsyncEnumerable`1<T>,System.Func`2<T,System.Boolean>)
AllAsync(System.Collections.Generic.IAsyncEnumerable`1<T>,System.Func`2<T,System.Threading.Tasks.ValueTask`1<System.Boolean>>)
FirstAsync(System.Collections.Generic.IAsyncEnumerable`1<T>)
FirstOrDefaultAsync(System.Collections.Generic.IAsyncEnumerable`1<T>)
Of(System.Collections.Generic.IAsyncEnumerable`1<T>)
Select(System.Collections.Generic.IAsyncEnumerable`1<T>,System.Func`2<T,U>)
Select(System.Collections.Generic.IAsyncEnumerable`1<T>,System.Func`2<T,System.Threading.Tasks.ValueTask`1<U>>)
SelectMany(System.Collections.Generic.IAsyncEnumerable`1<T>,System.Func`2<T,System.Collections.Generic.IEnumerable`1<U>>)
SelectMany(System.Collections.Generic.IAsyncEnumerable`1<T>,System.Func`2<T,System.Collections.Generic.IAsyncEnumerable`1<U>>)
SelectMany(System.Collections.Generic.IAsyncEnumerable`1<T>,System.Func`2<T,System.Threading.Tasks.Task`1<System.Collections.Generic.IEnumerable`1<U>>>)
SelectMany(System.Collections.Generic.IAsyncEnumerable`1<T>,System.Func`2<T,System.Threading.Tasks.Task`1<System.Collections.Generic.IAsyncEnumerable`1<U>>>)
Skip(System.Collections.Generic.IAsyncEnumerable`1<T>,System.Int32)
Skip(System.Collections.Generic.IAsyncEnumerable`1<T>,System.Int64)
SkipWhile(System.Collections.Generic.IAsyncEnumerable`1<T>,System.Func`2<T,System.Boolean>)
SkipWhile(System.Collections.Generic.IAsyncEnumerable`1<T>,System.Func`2<T,System.Threading.Tasks.ValueTask`1<System.Boolean>>)
Take(System.Collections.Generic.IAsyncEnumerable`1<T>,System.Int32)
Take(System.Collections.Generic.IAsyncEnumerable`1<T>,System.Int64)
TakeWhile(System.Collections.Generic.IAsyncEnumerable`1<T>,System.Func`2<T,System.Boolean>)
TakeWhile(System.Collections.Generic.IAsyncEnumerable`1<T>,System.Func`2<T,System.Threading.Tasks.Task`1<System.Boolean>>)
AddToCollectionAsync(System.Collections.Generic.IAsyncEnumerable`1<T>,TCollection,System.Action`2<TCollection,T>)
AddToCollectionAsync(System.Collections.Generic.IAsyncEnumerable`1<T>,TCollection,System.Func`3<TCollection,T,System.Threading.Tasks.Task>)
ToArrayAsync()
ToListAsync()
ToDictionaryAsync()
ToDictionaryAsync()
>c__DisplayClass31_0`3/<<ToDictionaryAsync()
AddToConcurrentCollectionAsync(System.Collections.Generic.IAsyncEnumerable`1<T>,TCollection,System.Action`2<TCollection,T>)
AddToConcurrentCollectionAsync(System.Collections.Generic.IAsyncEnumerable`1<T>,TCollection,System.Func`3<TCollection,T,System.Threading.Tasks.Task>)
ToConcurrentBagAsync()
ToConcurrentQueueAsync()
ToConcurrentStackAsync()
ToConcurrentBagAsync()
>c__DisplayClass37_0`2/<<ToConcurrentBagAsync()
ToConcurrentQueueAsync()
>c__DisplayClass38_0`2/<<ToConcurrentQueueAsync()
ToConcurrentStackAsync()
>c__DisplayClass39_0`2/<<ToConcurrentStackAsync()
ToConcurrentDictionaryAsync()
ToConcurrentDictionaryAsync()
>c__DisplayClass41_0`3/<<ToConcurrentDictionaryAsync()
Where(System.Collections.Generic.IAsyncEnumerable`1<T>,System.Func`2<T,System.Boolean>)
Where(System.Collections.Generic.IAsyncEnumerable`1<T>,System.Func`2<T,System.Threading.Tasks.Task`1<System.Boolean>>)
EnumerateAsync()
EnumerateAsync()
EnumerateAsync(System.Collections.Generic.IAsyncEnumerable`1<T>,System.Func`2<T,System.Boolean>)
EnumerateAsync(System.Collections.Generic.IAsyncEnumerable`1<T>,System.Func`2<T,System.Threading.Tasks.Task`1<System.Boolean>>)
EnumerateAsync(System.Collections.Generic.IAsyncEnumerable`1<T>)