我想要在 Scala 2.9.3 中将 (k,v) 元组的嵌套列表转换为 (v,k) 的平面列表。我尝试将所需的函数文字放在 flatMap 中。但是会发生这种情况:
scala> List( List( (1,"123"), (1,"abc")), List( (45, "qwer")) ).flatMap{ case (k,v) => (v,k) }
<console>:16: error: constructor cannot be instantiated to expected type;
found : (T1, T2)
required: List[(Int, java.lang.String)]
List( List( (1,"123"), (1,"abc")), List( (45, "qwer")) ).flatMap{ case (k,v) => (v,k) }
^
<console>:16: error: not found: value v
List( List( (1,"123"), (1,"abc")), List( (45, "qwer")) ).flatMap{ case (k,v) => (v,k) }
^
<console>:16: error: not found: value k
List( List( (1,"123"), (1,"abc")), List( (45, "qwer")) ).flatMap{ case (k,v) => (v,k) }
^
为什么这会发生在我身上?