소스 검색

Added QueueExtensions Utility class

frogsoftware 1 년 전
부모
커밋
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());
+        }
+        
+    }
+}