summaryrefslogtreecommitdiff
path: root/src/reflect
diff options
context:
space:
mode:
authorGeorge Leontiev <folone@gmail.com>2013-07-24 08:50:28 +0200
committerGeorge Leontiev <folone@gmail.com>2013-08-08 20:38:24 +0200
commitb145cb1c5d98cf7b01a145fa38c3e412e59f81b6 (patch)
tree2a62d6cb92c7033711494bb7c640fe239774993d /src/reflect
parente7876d5c41bbea0ee4679815edb5dc1ecef4c6a9 (diff)
downloadscala-b145cb1c5d98cf7b01a145fa38c3e412e59f81b6.tar.gz
scala-b145cb1c5d98cf7b01a145fa38c3e412e59f81b6.tar.bz2
scala-b145cb1c5d98cf7b01a145fa38c3e412e59f81b6.zip
Move map2Conserve to a new home, next to map2.
Diffstat (limited to 'src/reflect')
-rw-r--r--src/reflect/scala/reflect/internal/Types.scala15
-rw-r--r--src/reflect/scala/reflect/internal/util/Collections.scala12
2 files changed, 14 insertions, 13 deletions
diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala
index 11527d88ca..71f46fedb7 100644
--- a/src/reflect/scala/reflect/internal/Types.scala
+++ b/src/reflect/scala/reflect/internal/Types.scala
@@ -80,7 +80,8 @@ trait Types
with tpe.CommonOwners
with tpe.GlbLubs
with tpe.TypeMaps
- with tpe.TypeConstraints { self: SymbolTable =>
+ with tpe.TypeConstraints
+ with util.Collections { self: SymbolTable =>
import definitions._
import TypesStats._
@@ -4317,18 +4318,6 @@ trait Types
}
}
- /** like map2, but returns list `xs` itself - instead of a copy - if function
- * `f` maps all elements to themselves.
- */
- def map2Conserve[A <: AnyRef, B](xs: List[A], ys: List[B])(f: (A, B) => A): List[A] =
- if (xs.isEmpty || ys.isEmpty) xs
- else {
- val x1 = f(xs.head, ys.head)
- val xs1 = map2Conserve(xs.tail, ys.tail)(f)
- if ((x1 eq xs.head) && (xs1 eq xs.tail)) xs
- else x1 :: xs1
- }
-
/** Do type arguments `targs` conform to formal parameters `tparams`?
*/
def isWithinBounds(pre: Type, owner: Symbol, tparams: List[Symbol], targs: List[Type]): Boolean = {
diff --git a/src/reflect/scala/reflect/internal/util/Collections.scala b/src/reflect/scala/reflect/internal/util/Collections.scala
index e127d577e1..f32825252c 100644
--- a/src/reflect/scala/reflect/internal/util/Collections.scala
+++ b/src/reflect/scala/reflect/internal/util/Collections.scala
@@ -53,6 +53,18 @@ trait Collections {
}
lb.toList
}
+ /** like map2, but returns list `xs` itself - instead of a copy - if function
+ * `f` maps all elements to themselves.
+ */
+ final def map2Conserve[A <: AnyRef, B](xs: List[A], ys: List[B])(f: (A, B) => A): List[A] =
+ if (xs.isEmpty || ys.isEmpty) xs
+ else {
+ val x1 = f(xs.head, ys.head)
+ val xs1 = map2Conserve(xs.tail, ys.tail)(f)
+ if ((x1 eq xs.head) && (xs1 eq xs.tail)) xs
+ else x1 :: xs1
+ }
+
final def map3[A, B, C, D](xs1: List[A], xs2: List[B], xs3: List[C])(f: (A, B, C) => D): List[D] = {
if (xs1.isEmpty || xs2.isEmpty || xs3.isEmpty) Nil
else f(xs1.head, xs2.head, xs3.head) :: map3(xs1.tail, xs2.tail, xs3.tail)(f)