I am new in Scala programming and the flatmap function gives me headache.
Before you ask me to search, I made some research on Stackoverflow : https://stackoverflow.com/search?q=scala+map+to+list but I didn't find something to solve easily my problem.
Here is my problem :
For a scala programming project with Jacop (http://jacopguide.osolpro.com/guideJaCoP.html) ,
I need to convert this kind of map
Map[Int,List[List[IntVar]]]
to :
List[T]
// In my case , only a List[IntVar]
I know I should use several times flatMap but I wonder how correctly use that in my case.
Thanks for your help
If you want every
IntVar
from the values of the map, you could to this:The call to
values
returns anIterable
containing all the values of the map. In this case, it returns an object of typeIterable[List[List[IntVar]]]
. The firstflatten
-call on this object flattens it to anIterable[List[IntVar]]
. The secondflatten
-call flattens this object further to anIterable[IntVar]
. Finally, thetoList
method converts it to aList[IntVar]
.