Scala underscore minimal function

前端 未结 3 630

Let\'s create a value for the sake of this question:

val a = 1 :: Nil

now, I can demonstrate that the anonymous functions can be written in

3条回答
  •  被撕碎了的回忆
    2020-11-27 22:53

    You should use identity function for this use case.

    a.map(identity)
    

    identity is defined in scala.Predef as:

    implicit def identity[A](x: A): A = x 
    

提交回复
热议问题