Skip to content

Commit f00431f

Browse files
committed
fixup! adds groupUntilChanged extension method on scala.collection.Iterator
While considering the comments from the first review, I discovered that `readHead` was duplicating `Iterator#nextOption`
1 parent da65674 commit f00431f

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/main/scala/scala/collection/decorators/IteratorDecorator.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,22 @@ class IteratorDecorator[A](val `this`: Iterator[A]) extends AnyVal {
9595
*/
9696
def groupUntilChanged[K](f: A => K): Iterator[Iterable[A]] =
9797
new AbstractIterator[Seq[A]] {
98-
private var hd: Option[A] = readHead()
98+
private var hd: Option[A] = `this`.nextOption()
9999
override def hasNext: Boolean = hd.isDefined
100100

101101
override def next(): Seq[A] = {
102102
hd match {
103103
case None => Iterator.empty.next()
104104
case Some(head) =>
105105
val key = f(head)
106-
hd = readHead()
106+
hd = `this`.nextOption()
107107
var seq = mutable.Buffer(head)
108108
while (hd.exists(el => f(el) == key)) {
109109
seq = seq ++ hd
110-
hd = readHead()
110+
hd = `this`.nextOption()
111111
}
112112
seq.toVector
113113
}
114114
}
115-
116-
private def readHead() = if (`this`.hasNext) Some(`this`.next) else None
117115
}
118116
}

0 commit comments

Comments
 (0)