I have a series of map-like objects that I need to translate into keywords, and I've found core.match works really well for most cases, but there are a few cases where I need to match based on properties of combinations of fields, for example something like:
(match obj
{:a 0, :b 0, :c _} :foo
{:a 0, :b _, :c _} :bar
{:a a, :b b, :c (+ a b)} :baz)
Except that's not valid, and results in the error: AssertionError: Invalid list syntax a in (+ a b).
I tried using a guard instead, like:
(match obj
{:a 0, :b 0, :c _} :foo
{:a 0, :b _, :c _} :bar
{:a a, :b b, :c (_ :guard #(= % (+ a b)))} :baz)
But the bound symbols a and b are not available in the guard function: RuntimeException: Unable to resolve symbol: a in this context
Is there a way to do this with core.match? Or is there a better way?
Thanks in advance for any help.
Emlyn