Extract Tuple values on the fly
-
06-07-2021 - |
Pregunta
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.
Solución
(doFoo _).tupled(x)
or
Function.tupled(doFoo _)(x)
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow