summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksandar Pokopec <aleksandar.prokopec@epfl.ch>2010-11-08 08:52:14 +0000
committerAleksandar Pokopec <aleksandar.prokopec@epfl.ch>2010-11-08 08:52:14 +0000
commit056663c3f22b8c03f222856305ef99e3ed029889 (patch)
tree87d2f1cd1c822de80e26c9628bc9a69b08c38b8b
parent1016d68bef18ea078a83af6e550adf2d8a818ddd (diff)
downloadscala-056663c3f22b8c03f222856305ef99e3ed029889.tar.gz
scala-056663c3f22b8c03f222856305ef99e3ed029889.tar.bz2
scala-056663c3f22b8c03f222856305ef99e3ed029889.zip
Pruned away structural invocations throughout t...
Pruned away structural invocations throughout the collections framework. No review.
-rw-r--r--src/library/scala/collection/parallel/ParIterableLike.scala28
-rw-r--r--src/library/scala/collection/parallel/package.scala38
-rw-r--r--src/library/scala/util/control/Breaks.scala6
3 files changed, 62 insertions, 10 deletions
diff --git a/src/library/scala/collection/parallel/ParIterableLike.scala b/src/library/scala/collection/parallel/ParIterableLike.scala
index 681fe3570e..b312c953ad 100644
--- a/src/library/scala/collection/parallel/ParIterableLike.scala
+++ b/src/library/scala/collection/parallel/ParIterableLike.scala
@@ -221,8 +221,28 @@ self =>
type SSCTask[R, Tp] = StrictSplitterCheckTask[R, Tp]
+ /* helper traits - to avoid structural invocations */
+
+ trait TaskOps[R, Tp] {
+ def mapResult[R1](mapping: R => R1): ResultMapping[R, Tp, R1]
+ def compose[R3, R2, Tp2](t2: SSCTask[R2, Tp2])(resCombiner: (R, R2) => R3): SeqComposite[R, R2, R3, SSCTask[R, Tp], SSCTask[R2, Tp2]]
+ def parallel[R3, R2, Tp2](t2: SSCTask[R2, Tp2])(resCombiner: (R, R2) => R3): ParComposite[R, R2, R3, SSCTask[R, Tp], SSCTask[R2, Tp2]]
+ }
+
+ trait BuilderOps[Elem, To] {
+ trait Otherwise[Cmb] {
+ def otherwise(notbody: => Unit)(implicit m: ClassManifest[Cmb]): Unit
+ }
+
+ def ifIs[Cmb](isbody: Cmb => Unit): Otherwise[Cmb]
+ }
+
+ trait SignallingOps[PI <: DelegatedSignalling] {
+ def assign(cntx: Signalling): PI
+ }
+
/* convenience task operations wrapper */
- protected implicit def task2ops[R, Tp](tsk: SSCTask[R, Tp]) = new {
+ protected implicit def task2ops[R, Tp](tsk: SSCTask[R, Tp]) = new TaskOps[R, Tp] {
def mapResult[R1](mapping: R => R1): ResultMapping[R, Tp, R1] = new ResultMapping[R, Tp, R1](tsk) {
def map(r: R): R1 = mapping(r)
}
@@ -242,15 +262,15 @@ self =>
}
/* convenience signalling operations wrapper */
- protected implicit def delegatedSignalling2ops[PI <: DelegatedSignalling](it: PI) = new {
+ protected implicit def delegatedSignalling2ops[PI <: DelegatedSignalling](it: PI) = new SignallingOps[PI] {
def assign(cntx: Signalling): PI = {
it.signalDelegate = cntx
it
}
}
- protected implicit def builder2ops[Elem, To](cb: Builder[Elem, To]) = new {
- def ifIs[Cmb](isbody: Cmb => Unit) = new {
+ protected implicit def builder2ops[Elem, To](cb: Builder[Elem, To]) = new BuilderOps[Elem, To] {
+ def ifIs[Cmb](isbody: Cmb => Unit) = new Otherwise[Cmb] {
def otherwise(notbody: => Unit)(implicit m: ClassManifest[Cmb]) {
if (cb.getClass == m.erasure) isbody(cb.asInstanceOf[Cmb]) else notbody
}
diff --git a/src/library/scala/collection/parallel/package.scala b/src/library/scala/collection/parallel/package.scala
index 1a3b35c853..93f20132e5 100644
--- a/src/library/scala/collection/parallel/package.scala
+++ b/src/library/scala/collection/parallel/package.scala
@@ -48,21 +48,45 @@ package object parallel {
def par = mutable.ParArray.handoff[T](array)
}
- implicit def factory2ops[From, Elem, To](bf: CanBuildFrom[From, Elem, To]) = new {
+ trait FactoryOps[From, Elem, To] {
+ trait Otherwise[R] {
+ def otherwise(notbody: => R): R
+ }
+
+ def isParallel: Boolean
+ def asParallel: CanCombineFrom[From, Elem, To]
+ def ifParallel[R](isbody: CanCombineFrom[From, Elem, To] => R): Otherwise[R]
+ }
+
+ implicit def factory2ops[From, Elem, To](bf: CanBuildFrom[From, Elem, To]) = new FactoryOps[From, Elem, To] {
def isParallel = bf.isInstanceOf[Parallel]
def asParallel = bf.asInstanceOf[CanCombineFrom[From, Elem, To]]
- def ifParallel[R](isbody: CanCombineFrom[From, Elem, To] => R) = new {
+ def ifParallel[R](isbody: CanCombineFrom[From, Elem, To] => R) = new Otherwise[R] {
def otherwise(notbody: => R) = if (isParallel) isbody(asParallel) else notbody
}
}
- implicit def traversable2ops[T](t: TraversableOnce[T]) = new {
+ trait TraversableOps[T] {
+ trait Otherwise[R] {
+ def otherwise(notbody: => R): R
+ }
+
+ def isParallel: Boolean
+ def isParIterable: Boolean
+ def asParIterable: ParIterable[T]
+ def isParSeq: Boolean
+ def asParSeq: ParSeq[T]
+ def ifParSeq[R](isbody: ParSeq[T] => R): Otherwise[R]
+ def toParArray: ParArray[T]
+ }
+
+ implicit def traversable2ops[T](t: TraversableOnce[T]) = new TraversableOps[T] {
def isParallel = t.isInstanceOf[Parallel]
def isParIterable = t.isInstanceOf[ParIterable[_]]
def asParIterable = t.asInstanceOf[ParIterable[T]]
def isParSeq = t.isInstanceOf[ParSeq[_]]
def asParSeq = t.asInstanceOf[ParSeq[T]]
- def ifParSeq[R](isbody: ParSeq[T] => R) = new {
+ def ifParSeq[R](isbody: ParSeq[T] => R) = new Otherwise[R] {
def otherwise(notbody: => R) = if (isParallel) isbody(asParSeq) else notbody
}
def toParArray = if (t.isInstanceOf[ParArray[_]]) t.asInstanceOf[ParArray[T]] else {
@@ -73,7 +97,11 @@ package object parallel {
}
}
- implicit def throwable2ops(self: Throwable) = new {
+ trait ThrowableOps {
+ def alongWith(that: Throwable): Throwable
+ }
+
+ implicit def throwable2ops(self: Throwable) = new ThrowableOps {
def alongWith(that: Throwable) = self match {
case ct: CompositeThrowable => new CompositeThrowable(ct.throwables + that)
case _ => new CompositeThrowable(Set(self, that))
diff --git a/src/library/scala/util/control/Breaks.scala b/src/library/scala/util/control/Breaks.scala
index 0b83ac6d3b..5c735706b1 100644
--- a/src/library/scala/util/control/Breaks.scala
+++ b/src/library/scala/util/control/Breaks.scala
@@ -39,7 +39,11 @@ class Breaks {
}
}
- def tryBreakable(op: => Unit) = new {
+ trait TryBlock {
+ def catchBreak(onBreak: => Unit): Unit
+ }
+
+ def tryBreakable(op: => Unit) = new TryBlock {
def catchBreak(onBreak: => Unit) = try {
op
} catch {