Scala tuple function composition

Viewed 352

Let's say we have a 3 functions with Tuple3 result:

def foo(a: String, b: String, c: String): (String, String, String) = {
  (s"foo_$a", s"foo_$b", s"foo_$c")
}

def bar(a: String, b: String, c: String): (String, String, String) = {
  (s"bar_$a", s"bar_$b", s"bar_$c")
}

def buz(a: String, b: String, c: String): (String, String, String) = {
  (s"buz_$a", s"buz_$b", s"buz_$c")
}

And I can compose them like this:

val (a, b, c) = foo("1", "2", "3")
val (d, e, f) = bar(a, b, c)
val (g, h, i) = buz(d, e, f)

But I want something like this:

val (x, y, z) = foo(bar(buz("1", "2", "3")))

How can I achieve this?

3 Answers
Related