浏览代码

Added QueueExtensions Utility class

frogsoftware 11 月之前
父节点
当前提交
4a7ecf224d
共有 1 个文件被更改,包括 22 次插入0 次删除
  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());
+        }
+        
+    }
+}