Scala underscore explanation

本小妞迷上赌 提交于 2019-12-03 16:55:01

An amount of placeholders should be equals amount of function parameters. In your case map has 1 parameter that's why you can't use two placeholders.

Because List(List(1, 2), List(3, 4), List(5)) map ((_.size, _.size)) has a different meaning, namely

List(List(1, 2), List(3, 4), List(5)) map ((x => x.size, y => y.size))

(you can see this from the error message). This obviously doesn't compile, because map doesn't accept a tuple of two functions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!