Re: Data Transformation Question

2016-10-12 Thread tmountain
Thanks all. Much appreciated!

On Wednesday, October 12, 2016 at 11:26:09 AM UTC-4, tmountain 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"}}
>
> 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.


RE: Data Transformation Question

2016-10-12 Thread Aaron Cummings
You may also want to consider clojure.set/index, though that may not exactly be 
what you are looking for. 

 Original message 
From: tmountain <tinymount...@gmail.com> 
Date: 2016/10/12  11:26  (GMT-05:00) 
To: Clojure <clojure@googlegroups.com> 
Subject: Data Transformation Question 

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"}}
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.


Re: Data Transformation Question

2016-10-12 Thread Timothy Baldridge
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  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.


Data Transformation Question

2016-10-12 Thread tmountain
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"}}

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.


Re: Data Transformation Question

2016-10-12 Thread lvh


> On Oct 12, 2016, at 10:26 AM, tmountain  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.