Skip to content

Commit 5b9ed75

Browse files
authored
Merge pull request scala#5638 from som-snytt/issue/10137
SI-10137 Correct Queue.enqueue(collection.Iterable)
2 parents d56d66d + 7e49927 commit 5b9ed75

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/library/scala/collection/immutable/Queue.scala

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,14 @@ sealed class Queue[+A] protected(protected val in: List[A], protected val out: L
113113
*/
114114
def enqueue[B >: A](elem: B) = new Queue(elem :: in, out)
115115

116-
/** Returns a new queue with all elements provided by an `Iterable` object
117-
* added at the end of the queue.
116+
/** Creates a new queue with all elements provided by an `Iterable` object
117+
* added at the end of the old queue.
118118
*
119-
* The elements are prepended in the order they are given out by the
120-
* iterator.
119+
* The elements are prepended in the order they are given out by the iterator.
121120
*
122121
* @param iter an iterable object
123122
*/
124-
def enqueue[B >: A](iter: Iterable[B]) =
125-
new Queue(iter.toList reverse_::: in, out)
123+
def enqueue[B >: A](iter: scala.collection.Iterable[B]) = new Queue(iter.toList reverse_::: in, out)
126124

127125
/** Returns a tuple with the first element in the queue,
128126
* and a new queue with this element removed.

test/files/run/iq.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ qc: Queue(42, 0)
66
Head: 42
77
q5: Queue(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
88
q5[5]: 5
9+
q5alt: Queue(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
910
q5 == q5c: true
1011
q5c == q5: true
1112
q8: Queue(2, 3, 4, 5, 6, 7, 8, 9, 10, 11)

test/files/run/iq.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ object iq {
1616
Console.println("Empty")
1717
}
1818

19-
/* Test enqueing. */
19+
/* Test enqueueing. */
2020
val q2 = q.enqueue(42).enqueue(0)
2121
val qa = q :+ 42 :+ 0
2222
assert(q2 == qa)
@@ -45,7 +45,7 @@ object iq {
4545
q3
4646
}
4747

48-
/* Test sequence enqueing. */
48+
/* Test sequence enqueueing. */
4949
val q5: Queue[Any] = q4.enqueue(List(1,2,3,4,5,6,7,8,9))
5050
/* Test toString.
5151
* Expected: q5: Queue(0,1,2,3,4,5,6,7,8,9)
@@ -56,6 +56,10 @@ object iq {
5656
*/
5757
Console.println("q5[5]: " + q5(5))
5858

59+
val q5alt: Queue[Any] = q4.enqueue(collection.Iterable(1,2,3,4,5,6,7,8,9))
60+
Console.println("q5alt: " + q5alt)
61+
assert(q5alt.sameElements(q5))
62+
5963
val q5c: Queue[Int] = Queue.empty.enqueue(List(0, 1, 2, 3, 4, 5, 6, 7, 8, 9))
6064

6165
/* Testing ==

0 commit comments

Comments
 (0)