Re: Changing keys in a map

2010-10-02 Thread Sean Corfield
On Thu, Sep 30, 2010 at 11:54 PM, David Sletten da...@bosatsu.net wrote: Sean, Sean...I was just making fun of your signature. :) Phew! Just checking... (I'm on some lists where the response to similar questions has been You want me to do your homework?...) -- Sean A Corfield -- (904) 302-SEAN

Re: Changing keys in a map

2010-10-02 Thread Baishampayan Ghose
Sean, Sean...I was just making fun of your signature. :) Phew! Just checking... (I'm on some lists where the response to similar questions has been You want me to do your homework?...) The Clojure community is certainly not one of those. Regards, BG -- Baishampayan Ghose b.ghose at

Re: Changing keys in a map

2010-10-01 Thread David Sletten
On Oct 1, 2010, at 1:57 AM, Sean Corfield wrote: On Thu, Sep 30, 2010 at 12:52 AM, David Sletten da...@bosatsu.net wrote: Huh?! How many solutions do you want? You're starting to annoy me Sean. Sorry dude. I think it's really insightful to see lots of different solutions to small point

Changing keys in a map

2010-09-30 Thread Sean Corfield
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

Re: Changing keys in a map

2010-09-30 Thread Baishampayan Ghose
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 } What about this - (into {} (for [[k v] { :stuff 42 :like 13 :this 7 }]

Re: Changing keys in a map

2010-09-30 Thread David Sletten
On Sep 30, 2010, at 2:53 AM, Baishampayan Ghose wrote: 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 } What about this - (into

Re: Changing keys in a map

2010-09-30 Thread Sean Corfield
On Wed, Sep 29, 2010 at 11:53 PM, Baishampayan Ghose b.gh...@gmail.com wrote: (into {} (for [[k v] { :stuff 42 :like 13 :this 7 }]           [(.toUpperCase (name k)) v])) (defn- to-struct [r] (into {} (for [[k v] r] [(.toUpperCase (name k)) v])) That is certainly nicer than most of my

Re: Changing keys in a map

2010-09-30 Thread Baishampayan Ghose
On Wed, Sep 29, 2010 at 11:53 PM, Baishampayan Ghose b.gh...@gmail.com wrote: (into {} (for [[k v] { :stuff 42 :like 13 :this 7 }]           [(.toUpperCase (name k)) v])) (defn- to-struct [r] (into {} (for [[k v] r] [(.toUpperCase (name k)) v])) That is certainly nicer than most of my

Re: Changing keys in a map

2010-09-30 Thread Sean Corfield
On Thu, Sep 30, 2010 at 12:24 AM, Baishampayan Ghose b.gh...@gmail.com wrote: This also helps in avoiding the contrib dependency. Good point. Thanx BG. -- Sean A Corfield -- (904) 302-SEAN Railo Technologies, Inc. -- http://getrailo.com/ An Architect's View -- http://corfield.org/ If you're

Re: Changing keys in a map

2010-09-30 Thread Mark Engelberg
On Thu, Sep 30, 2010 at 12:24 AM, Baishampayan Ghose b.gh...@gmail.com wrote: clojure.contrib.string/upper-case is a trivial wrapper over .toUpperCase. In my humble opinion it's perfectly OK to use such static Java methods directly instead of writing trivial wrappers around them. Except that

Re: Changing keys in a map

2010-09-30 Thread Sean Corfield
On Thu, Sep 30, 2010 at 12:18 AM, Meikel Brandmeyer m...@kotka.de wrote: (defn to-string-keys  [m]  (zipmap (map (comp clojure.string/upper-case name) (keys m)) (vals m))) That's very similar to one of my attempts and... I don't know... I just don't like it as much. Splitting the map into two

Re: Changing keys in a map

2010-09-30 Thread Sean Corfield
On Thu, Sep 30, 2010 at 12:30 AM, Mark Engelberg mark.engelb...@gmail.com wrote: Except that if you use .toUpperCase, you have to remember to type hint the input.  Any time you call a Java method without type hinting, you take a significant performance hit.  The wrapper function takes care of

Re: Changing keys in a map

2010-09-30 Thread David Sletten
On Sep 30, 2010, at 3:40 AM, Sean Corfield wrote: On Thu, Sep 30, 2010 at 12:30 AM, Mark Engelberg mark.engelb...@gmail.com wrote: Except that if you use .toUpperCase, you have to remember to type hint the input. Any time you call a Java method without type hinting, you take a significant

Re: Changing keys in a map

2010-09-30 Thread Meikel Brandmeyer
Hi, On 30 Sep., 09:37, Sean Corfield seancorfi...@gmail.com wrote: That's very similar to one of my attempts and... I don't know... I just don't like it as much. Splitting the map into two streams and zipping them back together just doesn't feel as 'nice' and making one pass over the

Re: Changing keys in a map

2010-09-30 Thread nickikt
#(s/upper-case (name %)) Good and clear in this case. #(- % name s/upper-case) I think that would be nice if there were three functions. (comp s/upper-case name) I think its hard to read for beginners, because you have to read it backwards and no parens to indicate but you could say that the

Re: Changing keys in a map

2010-09-30 Thread Alex Miller
I wrote a blog recently on a helper function I use for stuff like this called mapmap: http://tech.puredanger.com/2010/09/24/meet-my-little-friend-mapmap/ mapmap takes a function to generate keys and a function to generate values, applies them to a sequence, and zipmaps their results. Using a map

Re: Changing keys in a map

2010-09-30 Thread Sean Corfield
On Thu, Sep 30, 2010 at 12:52 AM, David Sletten da...@bosatsu.net wrote: Huh?! How many solutions do you want? You're starting to annoy me Sean. Sorry dude. I think it's really insightful to see lots of different solutions to small point problems like this when you're learning a language -