Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // So, Scala Futures and Option wrappers ...
- // I'm curious about how to check the value of the Option `maybeFoundIt` while still returning a Result (Ok)
- someService.findByName(name="Looking for this").map(maybeFoundIt => {
- Ok(Json.toJson(maybeFoundIt))
- })
- // Map works here because we preserve the Future, which we want, so we just sneakily change the innards and return
- // but how do I check the return value (Option) and adjust my innard based upon that.
- // Matching is how you check Option right?
- // I know Scala likes pattern matching, but this returns a PartialFunction and we need a Future[Result] ¯\_(ツ)_/¯
- someService.findByName(name="Looking for this").map(maybeFoundIt => {
- case Some(gotIt) => Ok(Json.toJson(gotIt))
- case None => Ok(Json.toJson("status" -> "Not found"))
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement