Skip to content

Added more comments to make things easier to understand and maintain #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import scala.language.{higherKinds, implicitConversions}
*/
trait GenericParCompanion[+CC[X] <: ParIterable[X]] {

// `empty` and `apply` were previously inherited from `GenericCompanion` but this class
// has been removed in 2.13. I’ve copied their old implementation here.

/** An empty collection of type `$Coll[A]`
* @tparam A the type of the ${coll}'s elements
*/
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/scala/scala/collection/generic/ParFactory.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import scala.language.higherKinds
abstract class ParFactory[CC[X] <: ParIterable[X] with GenericParTemplate[X, CC]]
extends GenericParCompanion[CC] {

// The methods below were previously inherited from `GenTraversableFactory`, but this
// class has been removed in 2.13.

/** Concatenates all argument collections into a single $coll.
*
* @param xss the collections that are to be concatenated.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ extends GenericParMapCompanion[CC] {

type Coll = MapColl

// `apply` and `empty` methods were previously inherited from `GenMapFactory`, which
// has been removed from the Scala library in 2.13

/** A collection of type $Coll that contains given key/value bindings.
* @param elems the key/value pairs that make up the $coll
* @tparam K the type of the keys
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ self =>
def - (key: K): ParMap[K, S] = ParMap[K, S]() ++ this - key
}

// Transformation operations (`map`, `collect`, `flatMap` and `concat`) are overloaded
// to return a `ParMap` rather than a `ParIterable`

/** Builds a new map by applying a function to all elements of this $coll.
*
* @param f the function to apply to each element.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ self =>
*/
def endsWith[S >: T](that: Iterable[S]): Boolean = seq.endsWith(that)

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

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

/** Overload of ''union'' that takes a sequential collection as parameter */
def union[B >: T](that: scala.collection.Seq[B]): CC[B] = this ++ that

def padTo[U >: T](len: Int, elem: U): CC[U] = if (length < len) {
patch(length, new immutable.Repetition(elem, len - length), 0)
} else patch(length, ParSeq.newBuilder[U].result(), 0)
Expand Down
5 changes: 4 additions & 1 deletion junit/src/test/scala/MiscTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class MiscTest {
def si4761: Unit = {
val gs = for (x <- (1 to 5)) yield { if (x % 2 == 0) List(1) else List(1).par }
assertEquals("Vector(1, 1, 1, 1, 1)", gs.flatten.toString)
// assertEquals("Vector(Vector(1, 1, 1, 1, 1))", gs.transpose.toString)
// Commented because `transpose` require its argument to be convertible to an `Iterable` whereas
// we only have an `IterableOnce`
// assertEquals("Vector(Vector(1, 1, 1, 1, 1))", gs.transpose.toString)

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