Skip to content

Commit 7bc6f6e

Browse files
authored
Merge pull request #167 from xirc/throws-unsupported-operation-exception
2 parents 013eb07 + e578b77 commit 7bc6f6e

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

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

+6
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

@@ -463,10 +465,14 @@ extends IterableOnce[T @uncheckedVariance]
463465
}
464466

465467
def min[U >: T](implicit ord: Ordering[U]): T = {
468+
if (isEmpty) throw new UnsupportedOperationException("empty.min")
469+
466470
tasksupport.executeAndWaitResult(new Min(ord, splitter)).get.asInstanceOf[T]
467471
}
468472

469473
def max[U >: T](implicit ord: Ordering[U]): T = {
474+
if (isEmpty) throw new UnsupportedOperationException("empty.max")
475+
470476
tasksupport.executeAndWaitResult(new Max(ord, splitter)).get.asInstanceOf[T]
471477
}
472478

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

+26
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 )
@@ -127,4 +132,25 @@ class ParArrayTest extends scala.collection.concurrent.ctries_old.Spec {
127132
def `simple map test`: Unit = {
128133
assert(ParArray(1,2,3,4,5).map( (_:Int) * 10 ) == ParArray(10,20,30,40,50))
129134
}
135+
136+
@Test
137+
def `empty min`: Unit = {
138+
evaluating { ParArray.empty[Int].min }.shouldProduce[UnsupportedOperationException]()
139+
}
140+
141+
@Test
142+
def `empty max`: Unit = {
143+
evaluating { ParArray.empty[Int].max }.shouldProduce[UnsupportedOperationException]()
144+
}
145+
146+
@Test
147+
def `empty minBy`: Unit = {
148+
evaluating { ParArray.empty[String].minBy(_.length) }.shouldProduce[UnsupportedOperationException]()
149+
}
150+
151+
@Test
152+
def `emtpy maxBy`: Unit = {
153+
evaluating { ParArray.empty[String].maxBy(_.length) }.shouldProduce[UnsupportedOperationException]()
154+
}
155+
130156
}

0 commit comments

Comments
 (0)