Understanding `andThen`

前端 未结 1 1888
感情败类
感情败类 2021-02-02 10:17

I encountered andThen, but did not properly understand it.

To look at it further, I read the Function1.andThen docs

def andThen[A](g: (R) ⇒          


        
相关标签:
1条回答
  • 2021-02-02 11:14

    andThen is just function composition. Given a function f

    val f: String => Int = s => s.length
    

    andThen creates a new function which applies f followed by the argument function

    val g: Int => Int = i => i * 2
    
    val h = f.andThen(g)
    

    h(x) is then g(f(x))

    0 讨论(0)
提交回复
热议问题