I have a need to convert maps in the following ways:
Given a map with keyword keys, I need a map with uppercase string keys
- and vice versa.
{ :stuff 42 :like 13 :this 7 } <=> { "STUFF" 42 "LIKE" 13 "THIS" 7 }
I've come up with various functions to do this but so far they all
feel a bit clunky.
Any suggestions for the simplest, most idiomatic solution?
Here's one pair of functions I came up with...
(defn- to-struct [r] (apply hash-map (flatten (map (fn [[k v]]
[(s/upper-case (name k)) v]) r))))
(defn- to-rec [m] (apply hash-map (flatten (map (fn [[k v]] [(keyword
(s/lower-case k)) v]) m))))
s is clojure.string:
(:use [clojure.string :as s :only (lower-case upper-case)])
I came up with some using assoc and/or dissoc as well... didn't like
those much either :)
--
Sean A Corfield -- (904) 302-SEAN
Railo Technologies, Inc. -- http://getrailo.com/
An Architect's View -- http://corfield.org/
"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en