I am new to scala and want to get the following thing done using map, flatMap, and/or for comprehension.
I have a list of lists l = List[List[T]]
. For example, l = [[1,2,3],[2,4,6,4],[3,4,6,2,3]]
. Note that each list inside l
can have varying length.
Now I have val x: List[Int] = [1,2,3]
and I want to do some operation on x
and l
that returns [[1,1,2,3], [1,2,4,6,4], [1,3,4,6,2,3], [2,1,2,3], [2,2,4,6,4], [2,3,4,6,2,3], [3,1,2,3], [3,2,4,6,4], [3,3,4,6,2,3]]
(the order of sublists doesn't matter).
I feel like I should use map or flatMap or for-loop to do this but after a long time of trial I can't even get the type correct. Can anyone help me on it?