Why doesn't Function2 have an andThen method?

后端 未结 4 696
南笙
南笙 2021-02-13 04:12

Why does andThen only exist for single argument functions in Scala?

The following code works:

val double = (x: Int) => x * 2
val timesFou         


        
4条回答
  •  一向
    一向 (楼主)
    2021-02-13 05:01

    Another way to write theons's answer is to use:

    val multiplyAndDouble = double compose multiply.tupled
    val result = multiplyAndDouble(2, 6) // res 24
    

提交回复
热议问题