I recently read a new book by Manuel Bernhardt Jet Web Applications . In his book, he argues that Scala developers should never use .getto get an optional value.
I want to pick up his suggestions, but I try to avoid .getusing them for understanding for Futures.
Let's say I have the following code:
for {
avatarUrl <- avatarService.retrieve(email)
user <- accountService.save(Account(profiles = List(profile.copy(avatarUrl = avatarUrl)))
userId <- user.id
_ <- accountTokenService.save(AccountToken.create(userId, email))
} yield {
Logger.info("Foo bar")
}
I usually used AccountToken.create(user.id.get, email)instead AccountToken.create(userId, email). However, trying to avoid this bad practice, I get the following exception:
[error] found : Option[Nothing]
[error] required: scala.concurrent.Future[?]
[error] userId <- user.id
[error] ^
How can i solve this?
source
share