Last active
December 15, 2015 02:49
-
-
Save saml/5190419 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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