Hello,

I am trying to figure out how to make the following elegantly in clojure. 

I have a hash-map which has some key-value pairs and I would like to append 
to that hash-map a couple more key-value pairs IF some specific condition 
is met. For example, the create-map creates the main hash-map but i would 
like *to merge* the map with the value returned from create-key-value, if 
the condition inside that function is met.

(defn create-key-value [value] 

 (when (some-condition-true) {:extra-key "extra-value")) 

 

> (defn create-map [] 

    {:foo "a"

     :bar "b"}) 


The final, merged, map should look like this *if* create-key-value returned 
the :extra-key

{:foo "a", :bar "b", :extra-key "extra-value"}


...or if it didn't to return this:
 

>  {:foo "a", :bar "b"}


I did find a proposed solution on a stackoverflow 
post<http://stackoverflow.com/questions/8992997/initializing-elements-of-a-map-conditionally-in-clojure>,
 
but I am not sure if that's the most elegant way. 

Thank you for your time.

Regards,

Ryan

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to