diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/files/run/type-currying.check | 27 | ||||
-rw-r--r-- | test/files/run/type-currying.scala | 45 |
2 files changed, 72 insertions, 0 deletions
diff --git a/test/files/run/type-currying.check b/test/files/run/type-currying.check new file mode 100644 index 0000000000..e5db238ca5 --- /dev/null +++ b/test/files/run/type-currying.check @@ -0,0 +1,27 @@ +Map(abc -> 55) +(a,0) +(b,1) +(c,2) +(d,3) +(e,4) +(f,5) +(g,6) +(h,7) +(i,8) +(j,9) +(k,10) +(l,11) +(m,12) +(n,13) +(o,14) +(p,15) +(q,16) +(r,17) +(s,18) +(t,19) +(u,20) +(v,21) +(w,22) +(x,23) +(y,24) +(z,25) diff --git a/test/files/run/type-currying.scala b/test/files/run/type-currying.scala new file mode 100644 index 0000000000..717e0763a3 --- /dev/null +++ b/test/files/run/type-currying.scala @@ -0,0 +1,45 @@ +import scala.collection.{ mutable, immutable, generic } +import generic.CanBuildFrom + +object Partial { + type KnownContainer[CC[K, V] <: collection.Map[K, V]] = { + def values[V] : KnownValues[CC, V] + def apply[K] : KnownKeys[CC, K] + } + type KnownKeys[CC[K, V] <: collection.Map[K, V], K] = { + def apply[V](implicit cbf: CanBuildFrom[_, (K, V), CC[K, V]]): CC[K, V] + } + type KnownValues[CC[K, V] <: collection.Map[K, V], V] = { + def apply[K](implicit cbf: CanBuildFrom[_, (K, V), CC[K, V]]): CC[K, V] + } + + def apply[CC[K, V] <: collection.Map[K, V]] : KnownContainer[CC] = new { + def values[V] : KnownValues[CC, V] = new { + def apply[K](implicit cbf: CanBuildFrom[_, (K, V), CC[K, V]]) = cbf().result + } + def apply[K] = new { + def apply[V](implicit cbf: CanBuildFrom[_, (K, V), CC[K, V]]) = cbf().result + } + } +} + +object Test { + val m = Partial[immutable.TreeMap] + val m1 = m[String] + val m2 = m[Int][Int] + + val mutableBippy = Partial[mutable.HashMap][String][Int] + mutableBippy("abc") = 55 + + val immutableBippy = Partial[immutable.HashMap].values[Int] + def make[T](xs: T*) = immutableBippy[T] ++ xs.zipWithIndex + + val n0 = Partial[immutable.HashMap][String][Int] ++ Seq(("a", 1)) + val n1 = Partial.apply[immutable.HashMap].apply[String].apply[Int] ++ Seq(("a", 1)) + + def main(args: Array[String]): Unit = { + println(mutableBippy) + make('a' to 'z': _*).toList.sorted foreach println + assert(n0 == n1) + } +} |