Skip to content

Commit d1c3330

Browse files
committed
fixup! adds groupUntilChanged extension method on scala.collection.Iterator
1 parent 6462d1a commit d1c3330

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class IteratorDecorator[A](val `this`: Iterator[A]) extends AnyVal {
9393
* @return an iterator of sequences of the consecutive elements with the
9494
* same key in the original iterator
9595
*/
96-
def groupUntilChanged[K](f: A => K): Iterator[Iterable[A]] =
96+
def splitBy[K](f: A => K): Iterator[Iterable[A]] =
9797
new AbstractIterator[Seq[A]] {
9898
private var hd: Option[A] = `this`.nextOption()
9999
override def hasNext: Boolean = hd.isDefined

src/test/scala/scala/collection/decorators/IteratorDecoratorTest.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@ import org.junit.{Assert, Test}
77

88
class IteratorDecoratorTest {
99
@Test
10-
def groupUntilChangedShouldHonorEmptyIterator(): Unit ={
11-
val groupedIterator = Iterator.empty.groupUntilChanged(identity)
10+
def splitByShouldHonorEmptyIterator(): Unit ={
11+
val groupedIterator = Iterator.empty.splitBy(identity)
1212
Assert.assertFalse(groupedIterator.hasNext)
1313
Assert.assertEquals(Try(groupedIterator.next).toString, Try(Iterator.empty.next()).toString) }
1414
@Test
15-
def groupUntilChangedShouldReturnSingleSeqWhenAllElHaveTheSameKey(): Unit ={
15+
def splitByShouldReturnSingleSeqWhenAllElHaveTheSameKey(): Unit ={
1616
val value = Vector("1", "1", "1")
17-
val groupedIterator = value.iterator.groupUntilChanged(identity)
17+
val groupedIterator = value.iterator.splitBy(identity)
1818
Assert.assertTrue(groupedIterator.hasNext)
1919
Assert.assertEquals(groupedIterator.next.toVector, value)
2020
Assert.assertFalse(groupedIterator.hasNext)
2121
Assert.assertEquals(Try(groupedIterator.next).toString, Try(Iterator.empty.next()).toString)
2222
}
2323
@Test
24-
def groupUntilChangedShouldReturnSeqOfConsecutiveElementsWithTheSameKey(): Unit ={
24+
def splitByShouldReturnSeqOfConsecutiveElementsWithTheSameKey(): Unit ={
2525
val value = Vector("1", "2","2","3","3","3","2","2")
26-
val groupedIterator = value.iterator.groupUntilChanged(identity)
26+
val groupedIterator = value.iterator.splitBy(identity)
2727
Assert.assertTrue(groupedIterator.hasNext)
2828
Assert.assertEquals(groupedIterator.next.toVector, Vector("1"))
2929
Assert.assertTrue(groupedIterator.hasNext)

0 commit comments

Comments
 (0)