Somewhat similar to Stack Overflow question Compose and andThen methods, I\'ve been working through Twitter\'s Scala School tutorial and quickly ran into the same probl
You can use simply 'a compose b'.
scala> val c = a compose b
c: String => java.lang.String = <function1>
a(_).compose(b(_))
expands to x => { a(x).compose(y => b(y) }
. Hence the error. What you want is (x => a(x)).compose(y => b(y))
. Adding a pair of parentheses fixes this.
scala> (a(_)).compose(b(_: String))
res56: String => java.lang.String = <function1>
scala> res56("hello")
res57: java.lang.String = helloahemumm
But since a
and b
are functions, you can avoid all this cruft and simply do a compose b
.