Search code examples
scalatuplesextracton-the-fly

Extract Tuple values on the fly


Is there a way how I can extract values from a Tuple on the fly?

Let's assume the tuple:

val x = ("1", 2, "3")

and the method:

def doFoo(value1: String, value2: Int, value3: String)={}

How can I call doFoo() with the tuple 'x'? Something like doFoo(x), and the values in the tuple are extracted on the fly to match the method signature.


Solution

  • (doFoo _).tupled(x)
    

    or

    Function.tupled(doFoo _)(x)