Skip to content

Instantly share code, notes, and snippets.

@markhibberd
Forked from seanparsons/gist:4439489
Last active December 10, 2015 13:18
Show Gist options
  • Save markhibberd/4439507 to your computer and use it in GitHub Desktop.
Save markhibberd/4439507 to your computer and use it in GitHub Desktop.
val username: Option[String] \/ String = for {
parsed <- requestJson.parse.swapped(_.map(_.some)) // Parse the JSON.
jsonObject <- parsed.obj.toRight[Option[String]] // Get the JSON as a JsonObject instance.
userIDJson <- jsonObject("userid").toRight[Option[String]] // Get the "userid" field from the JsonObject.
userID <- userIDJson.string.toRight[Option[String]] // Get the value of the "userid" field.
user <- lookupUser(userID).toRight[Option[String]] // Get an instance of User for the user ID.
} yield user.username
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment