Ziqi Liu Ziqi Liu - 21 days ago 7
Scala Question

how to declare variable in scala lambda expression

in the method reduceByKey(), I was required to pass a function like this:

func:((String,Int),(String,Int))=>(String,Int)


and my code is

reduceByKey(((s1:String,i1:Int),(s2:String,i2:Int))=>(s1+s2,i1+i2))


however my IDE show strange error. Is there anything wrong with my code?

Answer

How does

reduceByKey({case((s1:String,i1:Int),(s2:String,i2:Int))=>(s1+s2,i1+i2)})

look in your IDE?