【发布时间】:2015-12-07 11:37:46
【问题描述】:
我无法通过一个reduce 操作让Point 类搜索x 坐标最大值(以下我使用map 然后reduce)
case class Point(x : Double, y : Double)
val pts = List(Point(1,3), Point(-3,2), Point(5,3))
pts.map(p => p.x).reduce( _ max _ )
这将返回
res22: Double = 5.0
如何使用单个reduce 操作来获得x 的最大值?我尝试了以下方法,但没有得到我期望的结果。
pts.reduce( _.x max _.x )
<console>:11: error: type mismatch;
found : Double
required: Point
【问题讨论】: