Reputation: 2317
I'm in the following situation. I would like a function to only be able to run in a given context. At the same time I would love to be able to compose these functions using the andThen
syntax (It would just look much better in this case).
So here is a small example for a worksheet. I would love to be able to do it the second way.
implicit val iInt: Int = 2
def a(a: String)(implicit ctx: Int): String = a
def b(b: String)(implicit ctx: Int): String = b
val works = b(a("foo"))
val fails = a("foo") andThen b
The general question would probably be. How does one compose curried functions? But if somebody can meet the requirements described in the first paragraph I would also be interested.
Upvotes: 1
Views: 133
Reputation: 938
This line works as you want with your definitions of a and b:
val worksToo = (a _ andThen b) ("foo")
a and b are transformed to functions (because there are not), then chained.
Upvotes: 1