Is there such function concatenation in scala?
I remember in Haskell dot "." can concat two function.
E.g. I want to achieve
def f1(a:String) = a.toInt
def f2(a:Int) = a + 1
def f3 = f1 . f2
f3("123")
Is there such function concatenation in scala?
I remember in Haskell dot "." can concat two function.
E.g. I want to achieve
def f1(a:String) = a.toInt
def f2(a:Int) = a + 1
def f3 = f1 . f2
f3("123")
In Scala, you can use andThen
to do this, like:
val f3 = f1 _ andThen f2 _
f3("123")
and Scala also has another method compose
to combine function
, compose
likes the andThen
function, but it call second function firstly and call the first function, like(f1(f2(_))`).
Reference: