这应该是一个容易的。我如何将函数应用于Scala中的元组? Viz:如何将函数应用于元组?
scala> def f (i : Int, j : Int) = i + j f: (Int,Int)Int scala> val p = (3,4) p: (Int, Int) = (3,4) scala> f p :6: error: missing arguments for method f in object $iw; follow this method with `_' if you want to treat it as a partially applied function f p ^ scala> f _ p :6: error: value p is not a member of (Int, Int) => Int f _ p ^ scala> (f _) p :6: error: value p is not a member of (Int, Int) => Int (f _) p ^ scala> f(p) :7: error: wrong number of arguments for method f: (Int,Int)Int f(p) ^ scala> grr!
非常感谢提前。
值得注意,斯卡拉(2.11.0这里)将带给您untupled PARAMS到一个元组,如果你这样做:'fft.apply(1,2)' – ThaDon 2014-09-11 12:57:23
好知道你可以做到这一点,但这似乎并不比仅仅使用'function(tup._1,tup._2)'更简短 – 2016-10-10 23:40:00
@AllenWang我认为重要的一点是'tupled'可以用于任何参数。良好的可维护性。 – Ohashi 2016-11-01 02:42:59