Procházet zdrojové kódy

Added QueueExtensions Utility class

frogsoftware před 11 měsíci
rodič
revize
4a7ecf224d
1 změnil soubory, kde provedl 22 přidání a 0 odebrání
  1. 22 0
      InABox.Core/QueueExtensions.cs

+ 22 - 0
InABox.Core/QueueExtensions.cs

@@ -0,0 +1,22 @@
+using System.Collections.Generic;
+using System.Linq;
+
+namespace InABox.Core
+{
+    public static class QueueExtensions
+    {
+        public static IEnumerable<T> Dequeue<T>(this Queue<T> queue, int chunkSize) 
+        {
+            for (int i = 0; i < chunkSize && queue.Count > 0; i++)
+            {
+                yield return queue.Dequeue();
+            }
+        }
+
+        public static Queue<T> ToQueue<T>(this IEnumerable<T> enumerable)
+        {
+            return new Queue<T>(enumerable.ToArray());
+        }
+        
+    }
+}