is there a better way to write the code below?
val t = map.get(\'type).getOrElse(\"\");
if (t != \"\") \"prefix\" + t;
be interested in inline
While reading the book Play for Scala, I picked up this code snippet that was defined in a controller, which might be a better syntax for getOrElse.
def show(ean: Long) = Action { implicit request =>
Product.findByEan(ean).map { product =>
Ok(views.html.products.details(product))
}.getOrElse(NotFound)
}
In which, the Product.findByEan(ean: Long) was defined like
def findByEan(ean: Long) = products.find(_ean == ean)