group-by is slightly different in that it wraps every value in a vector,
and those vectors will contain multiple items if there is an id collision.
So that may be what the OP wanted, but it also is a change in semantics.

I we can simplify the code a bit to (zipmap (map :id data) data) which is
about as simple as you are going to get.

Timothy

On Wed, Oct 12, 2016 at 9:29 AM, lvh <_...@lvh.io> wrote:

>
>
> On Oct 12, 2016, at 10:26 AM, tmountain <tinymount...@gmail.com> wrote:
>
> Hi, I'm trying to transform a sequence of data to a map, and I'm using the
> following pattern.
>
> (def data [ {:id 1, :name "foo"}, {:id 2, :name "bar"}])
>
> (zipmap (map #(:id %) data) data)
>
> ; result: {1 {:id 1, :name "foo"}, 2 {:id 2, :name "bar”}}
>
>
> Consider: (group-by :id data)
>
> Is this the most idiomatic way to accomplish this transformation? If not,
> what is?
>
> Thanks,
> Travis
>
> --
> 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/d/optout.
>
>
> --
> 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/d/optout.
>



-- 
“One of the main causes of the fall of the Roman Empire was that–lacking
zero–they had no way to indicate successful termination of their C
programs.”
(Robert Firth)

-- 
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/d/optout.

Reply via email to