I cannot get the Point
class to search for the x
coordinate maximum with one reduce
operation (the following I use map
then 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 _ )
This will return
res22: Double = 5.0
How to use a single reduce operation to get the max of x
out? I tried the following, but didn't get what I expect.
pts.reduce( _.x max _.x )
<console>:11: error: type mismatch;
found : Double
required: Point