GarfieldKlon
GarfieldKlon

Reputation: 12120

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.

Upvotes: 1

Views: 590

Answers (1)

missingfaktor
missingfaktor

Reputation: 92016

(doFoo _).tupled(x)

or

Function.tupled(doFoo _)(x)

Upvotes: 15

Related Questions