Python 3 will allow iterable unpacking such as:
>>> def foo(a, b, c): return a + b + c
...
>>> s1 = "one"
>>> s2 = ("two", "three")
>>> foo(s1, *s2)
'onetwothree'
I have seen How to apply a function to a tuple? and scala tuple unpacking but am having trouble emulating this in Scala (2.13):
scala> def foo(a: String, b: String, c: String): String = a + b + c
foo: (a: String, b: String, c: String)String
scala> val s1 = "one"
s1: String = one
scala> val s2 = Seq("two", "three")
s2: Seq[String] = List(two, three)
How can I mimic foo(s1, s2: _*)
?
The closest I've gotten is with this combination of uncurried/curried
, but frankly I'm not really understanding why this last attempt doesn't work:
scala> Function.uncurried((foo _).curried(s1))
res17: (String, String) => String = scala.Function$$$Lambda$897/0x0000000801070840@145f1f97
scala> Function.uncurried((foo _).curried(s1))(s2(0), s2(1))
res19: String = onetwothree
scala> Function.uncurried((foo _).curried(s1))(s2: _*)
^
error: not enough arguments for method apply: (v1: String, v2: String)String in trait Function2.
Unspecified value parameter v2.