Skip to content

Optional keys in the result #242

Open
@fhalde

Description

@fhalde

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions