Skip to content

Instantly share code, notes, and snippets.

@jonifreeman
Created August 17, 2011 16:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonifreeman/1151994 to your computer and use it in GitHub Desktop.
Save jonifreeman/1151994 to your computer and use it in GitHub Desktop.
JsonDSL vs. JsonAST
("lotto" ->
("lotto-id" -> lotto.id) ~
("winning-numbers" -> lotto.winningNumbers) ~
("winners" ->
lotto.winners.map { w =>
(("winner-id" -> w.id) ~
("numbers" -> w.numbers))}))
// vs.
JObject(List(
JField("lotto", JObject(List(
JField("lotto-id", lotto.id),
JField("winning-numbers", lotto.winningNumbers),
JField("winners",
lotto.winners.map { w =>
JObject(List(
JField("winner-id", w.id),
JField("numbers", w.numbers)))}))))))
/* Both generates:
{
"lotto":{
"lotto-id":5,
"winning-numbers":[2,45,34,23,7,5,3],
"winners":[{
"winner-id":23,
"numbers":[2,45,34,23,3,5]
},{
"winner-id":54,
"numbers":[52,3,12,11,18,22]
}]
}
}
*/
@raimohanska
Copy link

I'd prefer the third one below :) Would it be possible to make such an DSL in scala?

@jonifreeman
Copy link
Author

I'd prefer that too :) No way to make it work in Scala though.

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