关于函数式编程:Scala, find large list in a list | 珊瑚贝

Scala, find largest list in a list


假设 val a = List[List[int]]:
在 Scala 中查找包含最多元素的列表的最简洁方法是什么?


尝试 .maxBy 或 .maxByOption

之一

1
2
3
List(List(0)).maxBy(_.size) // List(0)
List(List(0)).maxByOption(_.size) // Some(List(0))
List.empty[List[Int]].maxByOption(_.size) // None

1
List(List(1), List(2, 3)).maxBy(_.size)


来源:https://www.codenong.com/61913523/

微信公众号
手机浏览(小程序)
0
分享到:
没有账号? 忘记密码?