After reading this excellent answer on for-expressions, I tried to convert my flatMap
to a for-expression
.
val results: List[String] = foo()
def getId: List[String] = List((json \ "_id").asOpt[String].getOrElse(""))
val xs: List[String] = results.flatMap( x => getId(Json.parse(x)))
Then, the for-expression.
val results: List[String] = foo()
def getId: List[String] = List((json \ "_id").asOpt[String].getOrElse(""))
val xs: List[String] = for {
r <- result
getId(Json.parse(r))
}
I get a compile-time error that <-
was expected on the getId(...)
line, but found }
.
What's wrong with my for expression?