Compose and andThen methods

后端 未结 4 418
长情又很酷
长情又很酷 2021-01-30 08:28

I\'m following the tutorial Pattern matching & functional composition on Scala compose and andThen methods. There\'s such an example:

4条回答
  •  南方客
    南方客 (楼主)
    2021-01-30 09:29

    addAhem is a method. compose method is defined on functions. addAhem _ converts addAhem from method to function, so compose can be called on it. compose expects a function as it's argument. You are giving it a method addUmm by converting addUmm into a function with addUmm _ (The underscore can be left out because the compiler can automatically convert a method into a function when it knows that a function is expected anyway). So your code:

    addAhem _ compose addUmm
    

    is the same as

    (addAhem _).compose(addUmm)
    

    but not

    addAhem(_).compose(addUmm(_))
    

    PS I didn't look at the link you provided.

提交回复
热议问题