I have an array
val L = Array((1,Array("one", "two")), (2, Array("one", "three")))
I can do this manipulation
val LL = L.map({case (s,Array(s1,s2))=>(s1,s2,1)})
I want to do the same thing but with arrays of an indeterminate number of elements. For example :
val L = Array((1,Array("one", "two", "three", "four")), (2, Array("one", "three")))
. This is just an example so basically I want a code that works for any array regardless of how many elements it has.
EDIT : I think I found a simple way to do it. As an example :
val L = Array((1,Array("one", "two", "three")), (2, Array("one", "three")))
val LL = L.flatMap({case (s,contents)=>(contents.map(s=>(s,1)))})
Instead of (s1,s2)
I just generalized it using the name contents then mapped the inner array contents inside a flatMap.