weavejester / medley

A lightweight library of useful Clojure functions
Eclipse Public License 1.0
870 stars 67 forks source link

Renaming keys in an associative collection by applying a fn #9

Closed jcoffin closed 10 years ago

jcoffin commented 10 years ago

Would that be something suitable for this library? Lately I've been needing a function like this:

(defn rename-keys [f coll]
  (zipmap (map f (keys coll))
          (vals coll)))

I'm not sure if that is a good name as it might be confused with clojure.set/rename-keys. What do you think?

jcoffin commented 10 years ago

Of course it is probably better to use into with empty so the result collection type matches the collection type passed in.

jcoffin commented 10 years ago

I just noticed that Prismatic's Plumbing has a map-keys function that seems to do this.

weavejester commented 10 years ago

Medley also has map-keys.

jcoffin commented 10 years ago

Bah! I can't believe I missed it! Sorry for the false alarm.