I'm a bit new to Scala I'm trying to convert the code block starting from if... which looks like Java to something more Scala like (I think a flatmap or case) but I was unable to create the correct result for the function. Any ideas? Thanks
override def getSubject[A](request: AuthenticatedRequest[A]): Future[Option[Subject]] = {
def parseResponse(body: JsValue): Option[User] = body.asOpt[User]
if(request.headers.keys.contains("user")) {
val jsonObject: JsValue = Json.parse(request.headers.get("user").get)
val userOptional: Option[User] = parseResponse(jsonObject)
Future.successful(userOptional)
} else {
Future.successful(None)
}
}
contains
to return an option