相关疑难解决方法(0)

应该避免x._1,x._2 ......语法吗?

我刚刚开始使用Scala.我发现自己经常使用元组变量.例如,这里是我写的一些代码:

/* Count each letter of a string and return in a list sorted by character
 * countLetter("test") = List(('e',1),('s',1),('t',2))
*/
def countLetters(s: String): List[(Char, Int)] = {
  val charsListMap = s.toList.groupBy((c:Char) => c)
  charsListMap.map(x => (x._1, x._2.length)).toList.sortBy(_._1)
}
Run Code Online (Sandbox Code Playgroud)

这个元组sytax(x._1,x._2等)是否受到Scala开发人员的不满?

scala

27
推荐指数
2
解决办法
6532
查看次数

标签 统计

scala ×1