Skip to content

Instantly share code, notes, and snippets.

@dgouyette
Last active August 29, 2015 14:09
Show Gist options
  • Save dgouyette/814dd4da109c6355d2a8 to your computer and use it in GitHub Desktop.
Save dgouyette/814dd4da109c6355d2a8 to your computer and use it in GitHub Desktop.
filterTransform
val objTransformer =
(__ \ "_embedded" \ "contract").json.copyFrom(
(__ \ "contract").readNullable[JsArray].map(_.getOrElse(JsArray()))
) and
(__ \ "_embedded" \ "comment").json.copyFrom(
(__ \ "comment").readNullable[Comment].filter(reviewOpt => isApproved(reviewOpt))
)
(__ \ "title").readNullable[String].map(_.fold(JsObject(Nil))(s => Json.obj("title" -> s)))
def isApproved(commentOpt : Option[Comment]) = {
(for {
comment <- commentOpt
status <- comment.status
} yield {
status==Status.approved
}).getOrElse(false)
}
@mandubian
Copy link

mais ça ne marche pas avec le orElse?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment