Skip to content

Instantly share code, notes, and snippets.

@tobnee
Created September 4, 2015 16:39
Show Gist options
  • Save tobnee/ca2bb15afed30695e30e to your computer and use it in GitHub Desktop.
Save tobnee/ca2bb15afed30695e30e to your computer and use it in GitHub Desktop.
Event evolutions as fold over evolution functions
val evolutions = List(
(v: JsObject) => v + ("a" -> JsString("foo")),
(v: JsObject) => v + ("b" -> JsNumber(2)),
(v: JsObject) => v - "a"
)
//evolutions: List[play.api.libs.json.JsObject => play.api.libs.json.JsObject] = List(<function1>, <function1>)
evolutions.foldLeft(Json.obj("msg" -> "Nice Evolution"))((value, evolution) => evolution(value))
// res1: play.api.libs.json.JsObject = {"msg":"Nice Evolution","b":2}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment