-
Notifications
You must be signed in to change notification settings - Fork 30
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
Scala 2.13.0 support #42
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package scala.collection | ||
|
||
private[collection] object DebugUtils { | ||
|
||
def buildString(closure: (Any => Unit) => Unit): String = { | ||
val output = new collection.mutable.StringBuilder | ||
closure { any => | ||
output ++= any.toString | ||
output += '\n' | ||
} | ||
|
||
output.result() | ||
} | ||
|
||
def arrayString[T](array: Array[T], from: Int, until: Int): String = { | ||
array.slice(from, until) map ({ | ||
case null => "n/a" | ||
case x => "" + x | ||
}: scala.PartialFunction[T, String]) mkString " | " | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* __ *\ | ||
** ________ ___ / / ___ Scala API ** | ||
** / __/ __// _ | / / / _ | (c) 2003-2013, LAMP/EPFL ** | ||
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** | ||
** /____/\___/_/ |_/____/_/ | | ** | ||
** |/ ** | ||
\* */ | ||
|
||
package scala | ||
package collection | ||
|
||
/** A marker trait for collections which have their operations parallelised. | ||
* | ||
* @since 2.9 | ||
* @author Aleksandar Prokopec | ||
*/ | ||
trait Parallel |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ package generic | |
import scala.collection.parallel.Combiner | ||
import scala.collection.parallel.ParIterable | ||
import scala.collection.parallel.ParMap | ||
import scala.language.higherKinds | ||
import scala.language.{higherKinds, implicitConversions} | ||
|
||
/** A template class for companion objects of parallel collection classes. | ||
* They should be mixed in together with `GenericCompanion` type. | ||
|
@@ -27,16 +27,82 @@ import scala.language.higherKinds | |
* @since 2.8 | ||
*/ | ||
trait GenericParCompanion[+CC[X] <: ParIterable[X]] { | ||
|
||
/** An empty collection of type `$Coll[A]` | ||
* @tparam A the type of the ${coll}'s elements | ||
*/ | ||
def empty[A]: CC[A] = newBuilder[A].result() | ||
|
||
/** Creates a $coll with the specified elements. | ||
* @tparam A the type of the ${coll}'s elements | ||
* @param elems the elements of the created $coll | ||
* @return a new $coll with elements `elems` | ||
*/ | ||
def apply[A](elems: A*): CC[A] = { | ||
if (elems.isEmpty) empty[A] | ||
else { | ||
val b = newBuilder[A] | ||
b ++= elems | ||
b.result() | ||
} | ||
} | ||
|
||
/** The default builder for $Coll objects. | ||
*/ | ||
def newBuilder[A]: Combiner[A, CC[A]] | ||
|
||
/** The parallel builder for $Coll objects. | ||
*/ | ||
def newCombiner[A]: Combiner[A, CC[A]] | ||
|
||
implicit def toFactory[A]: Factory[A, CC[A]] = GenericParCompanion.toFactory(this) | ||
|
||
} | ||
|
||
|
||
// TODO Specialize `Factory` with parallel collection creation methods so that the `xs.to(ParArray)` syntax | ||
// does build the resulting `ParArray` in parallel | ||
object GenericParCompanion { | ||
/** | ||
* Implicit conversion for converting any `ParFactory` into a sequential `Factory`. | ||
* This provides supports for the `to` conversion method (eg, `xs.to(ParArray)`). | ||
*/ | ||
implicit def toFactory[A, CC[X] <: ParIterable[X]](parFactory: GenericParCompanion[CC]): Factory[A, CC[A]] = | ||
new ToFactory(parFactory) | ||
|
||
@SerialVersionUID(3L) | ||
private class ToFactory[A, CC[X] <: ParIterable[X]](parFactory: GenericParCompanion[CC]) | ||
extends Factory[A, CC[A]] with Serializable{ | ||
def fromSpecific(it: IterableOnce[A]): CC[A] = (parFactory.newBuilder[A] ++= it).result() | ||
def newBuilder: mutable.Builder[A, CC[A]] = parFactory.newBuilder | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These conversions towards |
||
|
||
} | ||
|
||
trait GenericParMapCompanion[+CC[P, Q] <: ParMap[P, Q]] { | ||
|
||
def newCombiner[P, Q]: Combiner[(P, Q), CC[P, Q]] | ||
|
||
implicit def toFactory[K, V]: Factory[(K, V), CC[K, V]] = GenericParMapCompanion.toFactory(this) | ||
|
||
} | ||
|
||
object GenericParMapCompanion { | ||
/** | ||
* Implicit conversion for converting any `ParFactory` into a sequential `Factory`. | ||
* This provides supports for the `to` conversion method (eg, `xs.to(ParMap)`). | ||
*/ | ||
implicit def toFactory[K, V, CC[X, Y] <: ParMap[X, Y]]( | ||
parFactory: GenericParMapCompanion[CC] | ||
): Factory[(K, V), CC[K, V]] = | ||
new ToFactory[K, V, CC](parFactory) | ||
|
||
@SerialVersionUID(3L) | ||
private class ToFactory[K, V, CC[X, Y] <: ParMap[X, Y]]( | ||
parFactory: GenericParMapCompanion[CC] | ||
) extends Factory[(K, V), CC[K, V]] with Serializable { | ||
def fromSpecific(it: IterableOnce[(K, V)]): CC[K, V] = (parFactory.newCombiner[K, V] ++= it).result() | ||
def newBuilder: mutable.Builder[(K, V), CC[K, V]] = parFactory.newCombiner | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same with maps, to support |
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These methods (
empty
andapply
) were previously inherited fromGenericCompanion
, which has been removed from the standard library.