我在Scala中有一個任務,到目前爲止,這麼好。一切編譯除了這一點:Scala mapValues()類型不匹配
@transient val aggs = msgs.transform { rdd =>
val ts = rdd.map(quote => quote.ts).max() /// maximum of timestamp in the rdd
rdd.map{ q =>
((q.symbol,q.ts),(q.price,ts)) /// ((String, Long), (Double, Long)) structure
}
}
.reduceByKey{ (x,y) => (x._1 + y._1, x._2 + y._2) } // returns (Double, Long)
.mapValues((x: Double,y: Long) => (y.toDouble/x.toDouble)) // (Double, Long) => (Double)
.map{ case ((s,t),v) => (s,t,v)}
這件作品我卡上是mapValues()的匿名函數
:95: error: type mismatch;
found : (Double, Long) => Double
required: ((Double, Long)) => ?
任何人都可以點我在正確的方向?
我想也許是因爲'mapValues'你給了你的輸入一個特定的情況,但是如果它是默認情況,它會返回什麼? –