Regex unapply in for comprehension with if guard not compiling

Viewed 508

Why is that the following will not compile

for {
    s <- List.empty[String]
    regex <- List.empty[scala.util.matching.Regex]
    regex(ss) = s
    if ss == "foo"
} yield s

But removing the if

for {
    s <- List.empty[String]
    regex <- List.empty[scala.util.matching.Regex]
    regex(ss) = s
} yield s

or rearranging the order of the two lists in the for comprehension

for {
    regex <- List.empty[scala.util.matching.Regex]
    s <- List.empty[String]
    regex(ss) = s
    if ss == "foo"
} yield s

compiles?

Scalafiddle: http://scalafiddle.net/console/2519ff98d434cb522589f54a9c5fcf55

2 Answers
Related