Reputation: 3149
I would want to fill a Seq[Seq[Int]]
instance with an existing Seq[Int]
by using the method fill(n1, n2)(element : A)
of the Object Seq
, as detailed in the documentation : http://www.scala-lang.org/api/2.12.3/scala/collection/Seq$.html#fillA(elem:=>A):CC[CC[A]]
So I wrote this call :
Seq.fill(width, width)(_random_values.)
, with _random_values
the existing Seq[Int]
.
The problem is that the parameter of the second list of fill
is an element, not a Seq
. So, what could I type to iterate on each _random_values
's integers AND to execute the Seq.fill
for each current integer ?
Upvotes: 1
Views: 751
Reputation: 17433
Seq.fill
is more appropriate to create a Seq
base on a static value. For your use case Seq.grouped
might be a better fit:
val values: Seq[Int] = List(1, 2, 3, 4)
val result: Seq[Seq[Int]] = values.grouped(2).toSeq
result.foreach(println)
/*
List(1, 2)
List(3, 4)
*/
Upvotes: 5