Question on Pattern Matching

19 views
Skip to first unread message

Chetan Conikee

unread,
Aug 11, 2014, 7:24:16 PM8/11/14
to raptur...@googlegroups.com
Hi Jon


I stumbled on this issue and was wondering if I might be missing anything here

val s = """ { "name" : "bob" } """

//Works
Json.parse(s) match { case json""" { "name" : $n } """ => n }

//Does not work
Json.parse(s) match { case Json.parse(""" { "name" : $n } """) => n }

Am I missing anything here?


The reason I'd like to use this as I am building out generic function in order to substitute any pattern in 


Example:


val s = """ { "name" : "bob" } """

val attribute = "name"

val pattern = """ { """" + attribute + """" : $n }"""

Json.parse(s) match { case Json.parse(pattern) => n }


Would this be possible?

Jon Pretty

unread,
Aug 11, 2014, 10:23:18 PM8/11/14
to raptur...@googlegroups.com
Hi Chetan,

I've replied to the GitHub issue here:

   https://github.com/propensive/rapture-json/issues/15

For your particular example, though, it's not going to work as nicely as you would like, but it's given me an idea for how this could be better supported.

In ordinary Scala, we can write:

   val Regex = """he(.*)o""".r
   "hello" match { case Regex(x) => x }

I'll have think about whether I could do something similar for JSON...

Thanks for the inspiration!

Cheers,
Jon

Chetan Conikee

unread,
Aug 12, 2014, 2:07:21 AM8/12/14
to raptur...@googlegroups.com
As always, thanks for the prompt reply Jon.
Reply all
Reply to author
Forward
0 new messages