Skip to content

Instantly share code, notes, and snippets.

@saml
Last active December 15, 2015 02:49
Show Gist options
  • Save saml/5190419 to your computer and use it in GitHub Desktop.
Save saml/5190419 to your computer and use it in GitHub Desktop.
/*
Goal:
{
"portions": [{
"price": "$1"
}]
}
==> MenuItem(List(MenuItemPortion("$1")))
*/
case class MenuItemPortion(price: String)
case class MenuItem(portions: List[MenuItemPortion])
val o = MongoDBObject("portions" -> MongoDBList(MongoDBObject("price" -> "$1")))
o.getAs[MongoDBList]("portions").map(
portions => portions collect {
case portion:DBObject => portion.getAs[String]("price").map(
price => MenuItemPortion(price)) })
//res84: Option[scala.collection.mutable.Seq[Option[MenuItemPortion]]] = Some(ArrayBuffer(Some(MenuItemPortion($1))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment