I am currently working on a project with Scala, and it seems that I do not quite understand the Scala System: - /
I have the following situation:
def reviews(id: Int) = Action { implicit request => Ok(html.products.reviews( reviewlist, reviewlist .find(review => review.id == id) .getOrElse(reviewlist.headOption) )) }
Unfortunately, the compiler says that it cannot convert Product to Option [Review], so I changed the code
reviewlist .find(review => review.id == id) .getOrElse(reviewlist.headOption)
with
id match { case 0 => reviewlist.headOption case id => reviewlist.find(review => review.id == id) }
which seems to be working now, although its not quite the same as it is, for example, no longer showing the first record if an invalid validation ID is sent. he will pretend that there are no reviews yet.
Then I broke the problem down to a simple veeery sample:
val a: Option[Int] = Some(1).getOrElse(Some(1))
So, does anyone have an idea why the expression on the right side is not of type Option [Int]? Both, Some (1) and None inherit directly from Option, and is this expression actually Some (1) in either or am I mistaken?
Interesting enough
val a: Option[Int] = None.getOrElse(None)
works, but all other combinations do not ...
source share