Skip to content

Commit 7b80b65

Browse files
committed
Nil.reduce throws UnsupportedOperationException instead of NoSuchElementException
1 parent 013eb07 commit 7b80b65

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

core/src/main/scala/scala/collection/parallel/ParIterableLike.scala

+2
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,8 @@ extends IterableOnce[T @uncheckedVariance]
358358
* if this $coll is empty.
359359
*/
360360
def reduce[U >: T](op: (U, U) => U): U = {
361+
if (isEmpty) throw new UnsupportedOperationException("empty.reduce")
362+
361363
tasksupport.executeAndWaitResult(new Reduce(op, splitter)).get
362364
}
363365

junit/src/test/scala/scala/collection/parallel/mutable/ParArrayTest.scala

+5
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ class ParArrayTest extends scala.collection.concurrent.ctries_old.Spec {
8585
assert( ParArray(1,2,3,4,5).reduce(_+_) == 15 )
8686
}
8787

88+
@Test
89+
def `empty reduce`: Unit = {
90+
evaluating { ParArray.empty[Int].reduce(_+_) }.shouldProduce[UnsupportedOperationException]()
91+
}
92+
8893
@Test
8994
def `simple count`: Unit = {
9095
assert( ParArray[Int]().count(_ > 7) == 0 )

0 commit comments

Comments
 (0)