Skip to content

Instantly share code, notes, and snippets.

@bruntonspall
Created April 12, 2011 10:10
Show Gist options
  • Save bruntonspall/915282 to your computer and use it in GitHub Desktop.
Save bruntonspall/915282 to your computer and use it in GitHub Desktop.
This morning I turned ugly.scala into better.scala - still looking for a best.scala though
val optContacts = person.expand[BasicDBList]("contacts.pending")
for {
contacts <- optContacts;
contact <- contacts
if contact.isInstanceOf[DBObject]
pendingContact = contact.asInstanceOf[DBObject]
if pendingContact.expand[String]("contactId").get == contactId
} {
// Do stuff on contact and update mongo
}
person.expand[BasicDBList]("contacts.pending") map { contacts =>
contacts map { contact =>
contact match {
case pendingContact:DBObject => {
if (pendingContact.expand[String]("contactId").get == contactId) {
// Do stuff on contact and update mongo
}
}
case _ =>
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment