Scala FlatMap provides wrong results
问题 given a list of documents, I want to obtain the pairs that shares at least one token. To do this I wrote the code below, that do that through an inverted index. object TestFlatMap { case class Document(id : Int, tokens : List[String]) def main(args: Array[String]): Unit = { val documents = List( Document(1, List("A", "B", "C", "D")), Document(2, List("A", "B", "E", "F", "G")), Document(3, List("E", "G", "H")), Document(4, List("A", "L", "M", "N")) ) val expectedTokensIds = List(("A",1), ("A"