I have list of Integer like this:
val aRowcol: List[List[Int]]] = List(List(0, 0), List(0, 1), List(0, 2)), List(List(1, 0), List(1, 1), List(1, 2)), List(List(2, 0), List(2, 1), List(2, 2)), List(List(0, 0), List(1, 1), List(2, 2)), List(List(2, 0), List(1, 1), List(0, 2)), List(List(1, 0), List(0, 1), List(0, 2)), List(List(1, 0), List(2, 1), List(2, 2)) val aAlpha: List[List[String]] = List( List("a","b","c","d"), List("e","f","g","h"), List("i","j","k","l","m")) val i = 4 val resNum:List[List[Int,String]] = (0 to i) { _map => List( aRowcol.take(i).head.head, aRowcol.take(i).head(1), aAlpha(aRowcol.take(i).head.head)(aRowcol.take(i).head(1))} .toList But the result I want for val resNum is:
List( List(0,0,"a"), List(1,0,"e"), List(2,0,"i"), List(0,0,"a"), List(2,0,"i"))
(0,0) means first row first column, we have "a" on that possition, so i will define how many aAlpha we will have. I think it will be much easier if we do i++, but you know that we couldn't do i++ in scala.
list.take(i).headis equivalent tolist.head, becausetake(n)returns the first n items andheadreturns the first - so "first of first n" is the same as just "first"aRowcolbeList[List[List[Int]]]? Your sample code doesn't compile...aNumber listin the code sample