summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan@lightbend.com>2016-07-05 14:12:25 -0700
committerGitHub <noreply@github.com>2016-07-05 14:12:25 -0700
commit7644f1091b6f4e46f8290d8ad66ab2045f3ed448 (patch)
tree1a5a104d502b83c990a18d4acd09fcae09f23155
parent6612ba010b0e70c53550d1e47141c8dc89a55f23 (diff)
parentcf0390d94e59c637ba83170232864b069b90474e (diff)
downloadscala-7644f1091b6f4e46f8290d8ad66ab2045f3ed448.tar.gz
scala-7644f1091b6f4e46f8290d8ad66ab2045f3ed448.tar.bz2
scala-7644f1091b6f4e46f8290d8ad66ab2045f3ed448.zip
Merge pull request #5228 from dpogretskiy/SI-9817
SI-9817 immutable queue `forall` and `exists` implementations
-rw-r--r--src/library/scala/collection/immutable/Queue.scala8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/library/scala/collection/immutable/Queue.scala b/src/library/scala/collection/immutable/Queue.scala
index 3ad6656636..1dd0d7683a 100644
--- a/src/library/scala/collection/immutable/Queue.scala
+++ b/src/library/scala/collection/immutable/Queue.scala
@@ -84,6 +84,14 @@ sealed class Queue[+A] protected(protected val in: List[A], protected val out: L
else if (in.nonEmpty) new Queue(Nil, in.reverse.tail)
else throw new NoSuchElementException("tail on empty queue")
+ /* This is made to avoid inefficient implementation of iterator. */
+ override def forall(p: A => Boolean): Boolean =
+ in.forall(p) && out.forall(p)
+
+ /* This is made to avoid inefficient implementation of iterator. */
+ override def exists(p: A => Boolean): Boolean =
+ in.exists(p) || out.exists(p)
+
/** Returns the length of the queue.
*/
override def length = in.length + out.length