Advertisement
Guest User

for comprehension problem

a guest
Mar 11th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.44 KB | None | 0 0
  1. def findOne(id: BSONObjectID): Future[Option[reactive.models.User]] = {
  2.     val query = BSONDocument("_id" -> id)
  3.     val cursor = users.find(query).cursor[BSONDocument]
  4.  
  5.     for {
  6.       // get a future option of user
  7.       maybeUser <- cursor.headOption
  8.       // if there is some user, return a future of result with the user
  9.       result <- maybeUser.map { doc =>
  10.         Option(userReader.read(doc))
  11.       }.get
  12.  
  13.     } yield result
  14.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement