Skip to content

Commit a688fd4

Browse files
authored
Merge pull request #54 from julienrf/more-comments
Added more comments to make things easier to understand and maintain
2 parents e3d7ac6 + e652474 commit a688fd4

File tree

6 files changed

+20
-2
lines changed

6 files changed

+20
-2
lines changed

core/src/main/scala/scala/collection/generic/GenericParCompanion.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ import scala.language.{higherKinds, implicitConversions}
2828
*/
2929
trait GenericParCompanion[+CC[X] <: ParIterable[X]] {
3030

31+
// `empty` and `apply` were previously inherited from `GenericCompanion` but this class
32+
// has been removed in 2.13. I’ve copied their old implementation here.
33+
3134
/** An empty collection of type `$Coll[A]`
3235
* @tparam A the type of the ${coll}'s elements
3336
*/

core/src/main/scala/scala/collection/generic/ParFactory.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ import scala.language.higherKinds
3030
abstract class ParFactory[CC[X] <: ParIterable[X] with GenericParTemplate[X, CC]]
3131
extends GenericParCompanion[CC] {
3232

33+
// The methods below were previously inherited from `GenTraversableFactory`, but this
34+
// class has been removed in 2.13.
35+
3336
/** Concatenates all argument collections into a single $coll.
3437
*
3538
* @param xss the collections that are to be concatenated.

core/src/main/scala/scala/collection/generic/ParMapFactory.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ extends GenericParMapCompanion[CC] {
3535

3636
type Coll = MapColl
3737

38+
// `apply` and `empty` methods were previously inherited from `GenMapFactory`, which
39+
// has been removed from the Scala library in 2.13
40+
3841
/** A collection of type $Coll that contains given key/value bindings.
3942
* @param elems the key/value pairs that make up the $coll
4043
* @tparam K the type of the keys

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ self =>
191191
def - (key: K): ParMap[K, S] = ParMap[K, S]() ++ this - key
192192
}
193193

194+
// Transformation operations (`map`, `collect`, `flatMap` and `concat`) are overloaded
195+
// to return a `ParMap` rather than a `ParIterable`
196+
194197
/** Builds a new map by applying a function to all elements of this $coll.
195198
*
196199
* @param f the function to apply to each element.

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ self =>
325325
*/
326326
def endsWith[S >: T](that: Iterable[S]): Boolean = seq.endsWith(that)
327327

328+
/** Overload of ''patch'' that takes a sequential collection as parameter */
328329
def patch[U >: T](from: Int, patch: scala.collection.Seq[U], replaced: Int): CC[U] = patch_sequential(from, patch, replaced)
329330

330331
def patch[U >: T](from: Int, patch: ParSeq[U], replaced: Int): CC[U] = {
@@ -387,9 +388,11 @@ self =>
387388
* @return a new $coll which contains all elements of this $coll
388389
* followed by all elements of `that`.
389390
*/
390-
def union[B >: T](that: scala.collection.Seq[B]): CC[B] = this ++ that
391391
def union[B >: T](that: ParSeq[B]): CC[B] = this ++ that
392392

393+
/** Overload of ''union'' that takes a sequential collection as parameter */
394+
def union[B >: T](that: scala.collection.Seq[B]): CC[B] = this ++ that
395+
393396
def padTo[U >: T](len: Int, elem: U): CC[U] = if (length < len) {
394397
patch(length, new immutable.Repetition(elem, len - length), 0)
395398
} else patch(length, ParSeq.newBuilder[U].result(), 0)

junit/src/test/scala/MiscTest.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ class MiscTest {
2424
def si4761: Unit = {
2525
val gs = for (x <- (1 to 5)) yield { if (x % 2 == 0) List(1) else List(1).par }
2626
assertEquals("Vector(1, 1, 1, 1, 1)", gs.flatten.toString)
27-
// assertEquals("Vector(Vector(1, 1, 1, 1, 1))", gs.transpose.toString)
27+
// Commented because `transpose` require its argument to be convertible to an `Iterable` whereas
28+
// we only have an `IterableOnce`
29+
// assertEquals("Vector(Vector(1, 1, 1, 1, 1))", gs.transpose.toString)
2830

2931
val s = LazyList(Vector(1).par, Vector(2).par)
3032
assertEquals("List(1, 2)", s.flatten.toList.toString)
@@ -86,6 +88,7 @@ class MiscTest {
8688
def check[T](i: Int, f: Int => T): Unit = {
8789
val gseq = seqarr(i).toSeq.groupBy(f)
8890
val gpar = pararr(i).groupBy(f)
91+
// Note: sequential and parallel collections can not be compared with ''==''
8992
assertTrue(gseq.forall { case (k, vs) => gpar.get(k).exists(_.sameElements(vs)) })
9093
assertTrue(gpar.forall { case (k, vs) => gseq.get(k).exists(_.sameElements(vs)) })
9194
}

0 commit comments

Comments
 (0)