Why doesn't Function2 have an andThen method?

后端 未结 4 685
南笙
南笙 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 04:52

    I can't speak as to why Function2 doesn't supply and andThen, but Scalaz defines Functor instances for functions of various arities where map is equivalent to andThen, meaning you could write

    val multiplyAndDouble = multiply map double
    

提交回复
热议问题