Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional keys in the result #242

Open
fhalde opened this issue Apr 22, 2023 · 0 comments
Open

Optional keys in the result #242

fhalde opened this issue Apr 22, 2023 · 0 comments

Comments

@fhalde
Copy link

fhalde commented Apr 22, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant