scala/scala — pull request #3146 by ziggystar (2013-11-15 09:12:14+00:00)
Title: add `dequeueOption` to immutable.Queue

Currently it's not possible to use `immutable.Queue` easily in a functional way, since the essential method `deque` throws an exception is normal situation (dequeue on an empty Queue). Of course you can convert the exception into an Option on the user-side, but this is awkward to code, and simply annoying.

This pull-request implements `dequeueOption` in the spirit of `headOption` for `Seq`, yielding `Option[(A,Queue[A])]`, with `None` in case of empty queue.

A possible different type signature might have been `(Option[A],Queue[A])`, though this appears a bit strange, since `q.dequeueOption._2` would return `q` for the empty case and `q` with first element removed, else.