Note that if f is not referentially transparent, you can get different results depending on the order in which the collection is traversed, for unordered collections. See the API function group-by. It makes this behavior explicit by mapping each input argument to a vector of output arguments, in the same order as their corresponding inputs were traversed.
- Will Morgan On Aug 16, 3:31 am, Alan <a...@malloys.org> wrote: > (defn apply-keys [f ks] > (zipmap ks (map f ks))) > > Trivial to write, but it can be quite useful. For example: > (defn whatever [arg] > (let [some-list (make-list-from arg) > mapped (map myfunc some-list)] > (zipmap some-list mapped))) > > compared to > > (defn whatever [arg] > (apply-keys myfunc (make-list-from arg))) > > I was working on my project and found myself doing this fairly often; > I searched high and low in clojure.core and clojure.contrib but > couldn't find anything similar. This amazed me, because it seems so > common and generic that I assumed clojure would do it for me. If this > isn't already in a standard library, I'd like to see it added. I'm > happy to give it away to someone who maintains a package that would > "fit" this function, or if someone wants to explain to me how to add > my own package I'm willing to do that. > > Does this seem useful to anyone else? -- 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