Reputation: 17
Using Scala, I have got this error "value map is not a member of chemins.Point" point <- segment.to
Here is my code :
package chemins
case class Point(name: String, x: Long, y: Long)
case class Segment(from: Point, to: Point) {
def distance: Double = {
math.sqrt((from.x - to.x)*(from.x - to.x) + (from.y - to.y)*(from.y - to.y))
}
}
case class Path(segments: Vector[Segment]) {
def length: Double = {
(for {
segment <- segments
} yield segment.distance).sum
}
def stops : Vector[Point] = {
for {
segment <- segments
point <- segment.to
} yield point
}
}
From my previous search, it seems to come from the fact that "to" has no generator but I have no clues if it's relevant.
Thanks !
Upvotes: 1
Views: 2520
Reputation: 44908
Without looking at the chemins
api, you most likely want
for { segment <- segments } yield segment.to
or
for {
segment <- segments
point = segment.to
} yield point
Trying to use segment.to
as a generator makes no sense, because it's not a collection or a .map
-pable entity.
Also note that this for-comprehension reduces to
segments.map(_.to)
Upvotes: 3