As indicated in the header, I want to have a method that can be applied to any argument of type Array[Array[_]]either Seq[Array[_]]or Array[Seq[_]]or or Seq[Seq[_]]. The argument must be turned into a 2D array ( Array[Array[_]]), thus changing the type of collections involved.
I have the following signature, which apparently accepts any such combination, but I cannot build arrays.
def apply[A: Manifest, S[_] <: Seq[_], U <% S[S[A]]](components: U): CombinationIterator[A] = {
new CombinationIterator(Array(components.map((s: S[A]) => s.toArray)))
}
The class CombinationIteratortakes as an argument Array[Array[T]]. I get the following error:
error: could not find implicit value for evidence parameter of type ClassManifest[A]
new CombinationIterator(Array(components.map((s: S[A]) => s.toArray)))
For completeness, here is the constructor; perhaps this is important because it Ais required Manifest.
class CombinationIterator[A: Manifest](components: Array[Array[A]]) extends Iterator[Array[A]]
failed REPL session
The following works for Array[Seq[_]], but not for Seq[Array[_]]:
scala> def f[T:Manifest](s: Seq[Seq[T]]) = s.map(_.toArray).toArray
f: [T](s: Seq[Seq[T]])(implicit evidence$1: Manifest[T])Array[Array[T]]
scala> f(Array(Seq(1,2),Seq(3,4)))
res22: Array[Array[Int]] = Array(Array(1, 2), Array(3, 4))
scala> f(Seq(Array(1,2),Array(3,4)))
<console>:9: error: type mismatch;
found : Seq[Array[Int]]
required: Seq[Seq[?]]
f(Seq(Array(1,2),Array(3,4)))
^
() REPL didierd
scala> def f[T: Manifest, ST <% Seq[T]](s: Seq[ST]) = s.map(_.toArray).toArray
f: [T, ST](s: Seq[ST])(implicit evidence$1: Manifest[T], implicit evidence$2: (ST) => Seq[T])Array[Array[T]]
scala> f(Seq(Seq(1)))
<console>:9: error: No implicit view available from Seq[Int] => Seq[T].
f(Seq(Seq(1)))
^
,
. , . .
, implicits -.
object CombinationIterator {
case class AArray[T](aa: Array[Array[T]])
implicit def seqseq2AA[T: Manifest](ss: Seq[Seq[T]]) = AArray(ss.map(_.toArray).toArray)
implicit def seqarray2AA[T: Manifest](sa: Seq[Array[T]]) = AArray(sa.toArray)
def apply[T: Manifest](components : AArray[T]): CombinationIterator[T] = {
new CombinationIterator(components.aa)
}
}
, . . . , , - - "" , , Vector.