Given these definitions:
val guys = List("Albert", "Tom")
val girls = List("Mary", "Stacy", "Josie")
val optRoom: Option[String] = Some("Room 303")
This evaluates to me expected List[String]
:
for {
guy <- guys
girl <- girls
room <- optRoom
} yield {
s"$guy dances with $girl in $room"
}
Turning things a bit inside the loop, I would expect this to evaluate to an Option[List[String]]
, but it does not even compile:
for {
room <- optRoom
guy <- guys
girl <- girls
} yield {
s"$guy dances with $girl in $room"
}
Why not? What am I missing? (I know I can convert optRoot
to a sequence / list / iterable, but it's not what I want)
How should I rewrite my code to get Option[List[String]]
?