What are all the uses of an underscore in Scala?

后端 未结 7 1168
南笙
南笙 2020-11-21 07:24

I\'ve taken a look at the list of surveys taken on scala-lang.org and noticed a curious question: \"Can you name all the uses of “_”?\". Can you? If yes, please do so here.

7条回答
  •  灰色年华
    2020-11-21 07:38

    There is one usage I can see everyone here seems to have forgotten to list...

    Rather than doing this:

    List("foo", "bar", "baz").map(n => n.toUpperCase())
    

    You could can simply do this:

    List("foo", "bar", "baz").map(_.toUpperCase())
    

提交回复
热议问题