meander
meander copied to clipboard
Optional keys in the result
Is there a better way to achieve the following?
e..g assume I will get the following kinds of inputs
{:name "foo" :address {:postal 1111}}
{:name "bar" :address {:postal nil}}
and I want to transform it into the following map
#1 {:Name "foo" :postal 1111}
#2 {:Name "bar"}
i.e i don't want the key :postal
to even be present if the value of it is going to be nil
(m/match {:name "faiz" :addr {:postal nil}}
{:name ?name :addr {:postal ?post}}
(merge
{:Name ?name}
(when ?post
{:postal ?post})))
this was my initial attempt but the fact that i am writing some logic ( the how
) defeats the purpose of a declarative matcher such as meander