summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2013-12-08 21:01:27 -0800
committerAdriaan Moors <adriaan.moors@typesafe.com>2013-12-08 21:01:27 -0800
commit75cc6cf256df9e152eaec771121ce0db9f7039f8 (patch)
tree655acca49d7990fbc7c273d761ca942aa0ac651d /src/library
parent9751d19471c8ab7c1cc2a618fe097af9dddbd03b (diff)
parent58eadc09527c2b6722ddd830c0d3f319f2967ef7 (diff)
downloadscala-75cc6cf256df9e152eaec771121ce0db9f7039f8.tar.gz
scala-75cc6cf256df9e152eaec771121ce0db9f7039f8.tar.bz2
scala-75cc6cf256df9e152eaec771121ce0db9f7039f8.zip
Merge pull request #3226 from ziggystar/patch-1
add method dequeueOption to immutable.Queue
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/collection/immutable/Queue.scala7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/library/scala/collection/immutable/Queue.scala b/src/library/scala/collection/immutable/Queue.scala
index 05c5dd799d..df1484c4ab 100644
--- a/src/library/scala/collection/immutable/Queue.scala
+++ b/src/library/scala/collection/immutable/Queue.scala
@@ -118,6 +118,13 @@ class Queue[+A] protected(protected val in: List[A], protected val out: List[A])
case x :: xs => (x, new Queue(in, xs))
case _ => throw new NoSuchElementException("dequeue on empty queue")
}
+
+ /** Optionally retrieves the first element and a queue of the remaining elements.
+ *
+ * @return A tuple of the first element of the queue, and a new queue with this element removed.
+ * If the queue is empty, `None` is returned.
+ */
+ def dequeueOption: Option[(A, Queue[A])] = if(isEmpty) None else Some(dequeue)
/** Returns the first element in the queue, or throws an error if there
* is no element contained in the queue.