Summary

Class:AsyncEnumeration.Implementation.Enumerable.AsyncEnumerableFunctionalWrapper`2
Assembly:AsyncEnumeration.Implementation.Enumerable
File(s):/repo-dir/contents/Source/Code/AsyncEnumeration.Implementation.Enumerable/Generator.cs
Covered lines:11
Uncovered lines:0
Coverable lines:11
Total lines:151
Line coverage:100%
Tag:7d9974899246b95481b7aa9cd3a1462ae2a67c91

Coverage History

Metrics

MethodCyclomatic complexity NPath complexity Sequence coverage Branch coverage
.ctor(...)101%0%
System.Collections.Generic.IAsyncEnumerable<T>.GetAsyncEnumerator()101%0%

File(s)

/repo-dir/contents/Source/Code/AsyncEnumeration.Implementation.Enumerable/Generator.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.Implementation.Enumerable
 28{
 29
 30   /// <summary>
 31   /// This class implements <see cref="IAsyncEnumerable{T}"/> by using the given <see cref="IAsyncProvider"/> and callb
 32   /// </summary>
 33   /// <typeparam name="T">The type of items being enumerated.</typeparam>
 34   internal sealed class AsyncEnumerableFunctionalWrapper<T> : IAsyncEnumerable<T>
 35   {
 36      private readonly Func<IAsyncEnumerator<T>> _getEnumerator;
 37      private readonly IAsyncProvider _asyncProvider;
 38
 39      /// <summary>
 40      /// Creates a new instance of <see cref="AsyncEnumerableFunctionalWrapper{T}"/> with given callback.
 41      /// </summary>
 42      /// <param name="getEnumerator">The callback to create <see cref="IAsyncEnumerator{T}"/>.</param>
 43      /// <param name="asyncProvider">The <see cref="IAsyncProvider"/> to use.</param>
 44      /// <exception cref="ArgumentNullException">If either of <paramref name="getEnumerator"/> or <paramref name="async
 45      public AsyncEnumerableFunctionalWrapper(
 46         IAsyncProvider asyncProvider,
 47         Func<IAsyncEnumerator<T>> getEnumerator
 48         )
 49      {
 50         this._getEnumerator = ArgumentValidator.ValidateNotNull( nameof( getEnumerator ), getEnumerator );
 51         this._asyncProvider = ArgumentValidator.ValidateNotNull( nameof( asyncProvider ), asyncProvider );
 52      }
 53
 54      IAsyncProvider IAsyncEnumerable.AsyncProvider => this._asyncProvider;
 55
 56      IAsyncEnumerator<T> IAsyncEnumerable<T>.GetAsyncEnumerator() => this._getEnumerator();
 57   }
 58
 59   /// <summary>
 60   /// This class implements <see cref="IAsyncEnumerable{T}"/> by using the given <see cref="IAsyncProvider"/>, callback
 61   /// </summary>
 62   /// <typeparam name="T">The type of items being enumerated.</typeparam>
 63   /// <typeparam name="TArg">The type of argument for the callback.</typeparam>
 64   internal sealed class AsyncEnumerableFunctionalWrapper<T, TArg> : IAsyncEnumerable<T>
 65   {
 66      private readonly Func<TArg, IAsyncEnumerator<T>> _getEnumerator;
 67      private readonly IAsyncProvider _asyncProvider;
 68      private readonly TArg _arg;
 69
 70      /// <summary>
 71      /// Creates a new instance of <see cref="AsyncEnumerableFunctionalWrapper{T, TArg}"/> with given callback.
 72      /// </summary>
 73      /// <param name="arg">The argument for <paramref name="getEnumerator"/> callback.</param>
 74      /// <param name="getEnumerator">The callback to create <see cref="IAsyncEnumerator{T}"/>.</param>
 75      /// <param name="asyncProvider">The <see cref="IAsyncProvider"/> for the returned <see cref="IAsyncEnumerable{T}"/
 76      /// <exception cref="ArgumentNullException">If either of <paramref name="getEnumerator"/> or <paramref name="async
 3477      public AsyncEnumerableFunctionalWrapper(
 3478         IAsyncProvider asyncProvider,
 3479         TArg arg,
 3480         Func<TArg, IAsyncEnumerator<T>> getEnumerator
 3481         )
 82      {
 3483         this._arg = arg;
 3484         this._getEnumerator = ArgumentValidator.ValidateNotNull( nameof( getEnumerator ), getEnumerator );
 3485         this._asyncProvider = ArgumentValidator.ValidateNotNull( nameof( asyncProvider ), asyncProvider );
 3486      }
 87
 4288      IAsyncProvider IAsyncEnumerable.AsyncProvider => this._asyncProvider;
 89
 3490      IAsyncEnumerator<T> IAsyncEnumerable<T>.GetAsyncEnumerator() => this._getEnumerator( this._arg );
 91   }
 92
 93   //internal static class UtilPackExtensions2
 94   //{
 95   //   // TODO move to UtilPack
 96   //   public static Boolean TryAddWithLocking<TKey, TValue>( this IDictionary<TKey, TValue> dictionary, TKey key, TVal
 97   //   {
 98   //      lock ( lockObject ?? dictionary )
 99   //      {
 100   //         var retVal = !dictionary.ContainsKey( key );
 101   //         if ( retVal )
 102   //         {
 103   //            dictionary.Add( key, value );
 104   //         }
 105
 106   //         return retVal;
 107   //      }
 108   //   }
 109
 110   //   public static Boolean TryRemoveWithLocking<TKey, TValue>( this IDictionary<TKey, TValue> dictionary, TKey key, o
 111   //   {
 112   //      lock ( lockObject ?? dictionary )
 113   //      {
 114   //         var retVal = dictionary.ContainsKey( key );
 115   //         value = retVal ? dictionary[key] : default;
 116   //         dictionary.Remove( key );
 117   //         return retVal;
 118   //      }
 119   //   }
 120
 121   //   public static void AddWithLocking<TValue>( this IList<TValue> list, TValue item, Object lockObject = null )
 122   //   {
 123   //      lock ( lockObject ?? list )
 124   //      {
 125   //         list.Add( item );
 126   //      }
 127   //   }
 128
 129   //   public static Boolean TryPopWithLocking<TValue>( this IList<TValue> list, out TValue value, Object lockObject = 
 130   //   {
 131   //      lock ( lockObject ?? list )
 132   //      {
 133   //         var count = list.Count;
 134   //         var retVal = list.Count > 0;
 135
 136   //         value = retVal ? list[count - 1] : default;
 137   //         list.RemoveAt( count - 1 );
 138   //         return retVal;
 139   //      }
 140   //   }
 141
 142   //   public static void ClearWithLocking<TValue>( this ICollection<TValue> collection, Object lockObject = null )
 143   //   {
 144   //      lock ( lockObject ?? collection )
 145   //      {
 146   //         collection.Clear();
 147   //      }
 148   //   }
 149   //}
 150
 151}