This is my code. To my surprise, it yields a map instead of a seq of tuples as I expect. What is right way to get list of tuples in scala?
for ((_, s) <- Constants.sites;
line <- Source.fromFile(s"data/keywords/topkey$s.txt").getLines
) yield ((s, line))
The reason probably is that
Constants.sites
is aMap
, therefore it returns a map.Instead of running the comprehension over
Constants.sites
, run it overConstants.sites.values
, you are only using the values anyway.The background is that your code gets translated to:
And when calling
flatMap
onMap
your resulting type also needs to be aMap
, and the tuples can be coerced to aMap
.EDIT: But using this should be fine: