I'm new to scala and have been working to understand the syntax so that I can be more efficient. How does this look in terms of functional syntax and scala idioms?
In particular, I'd like to know if this is a good way of handling futures. I'm aware of onComplete, onSuccess, etc..., matching but I had trouble getting a return value back out. map seemed like the right approach here.
object Application extends Controller with securesocial.core.SecureSocial {
val inboxSlurper = Akka.system.actorOf(Props[InboxSlurper], name = "inboxSlurper")
def index = SecuredAction.async {
implicit request =>
implicit val timeout = Timeout(10 seconds)
val user: User = request.user.asInstanceOf[User]
val f = inboxSlurper.ask(
OauthIdentity(
user.email.get,
user.oAuth2Info.get.accessToken))
f flatMap { reply =>
val emailFeed = reply.asInstanceOf[Enumerator[Message]]
val iter = Iteratee.fold[Message, String]("")((result, msg) => result + msg.getSubject())
emailFeed |>>> iter
} map { str =>
Logger.debug(str);
val subj = "Subject: %s".format(str)
Ok(views.html.index(subj))
}
}
}