(map-indexed #(hash-map "id" %1 "value" %2) '(a b c))

or, if you don't want to use #()

(map-indexed (comp (partial zipmap ["id" "value"]) list) '(a b c))

On Fri, Jun 8, 2012 at 9:33 AM, Kevin Ilchmann Jørgensen
<kijm...@gmail.com>wrote:

> (map  #(hash-map :v %1 :id %2)  '(a b c c b a) (range))
> => ({:v a, :id 0} {:v b, :id 1} {:v c, :id 2} {:v c, :id 3} {:v b, :id
> 4} {:v a, :id 5})
>
> /k
>
> On Fri, Jun 8, 2012 at 3:31 PM, Jay Fields <j...@jayfields.com> wrote:
> > You probably just want map-indexed...
> >
> > Sent from my iPhone
> >
> > On Jun 8, 2012, at 9:24 AM, Christian Guimaraes <cguimaraes...@gmail.com
> >
> > wrote:
> >
> > Hello all,
> >
> > I have the code below:
> >
> > (def data
> >   '(a b c c b a))
> >
> > (for [value data] (hash-map "id" (.indexOf data value) "value" value))
> >
> > That gives me the output:
> >
> > ({"value" a, "id" 0} {"value" b, "id" 1} {"value" c, "id" 2} {"value" c,
> > "id" 0} {"value" b, "id" 1} {"value" a, "id" 2})
> >
> > but I need the following output:
> >
> > ({"value" a, "id" 0} {"value" b, "id" 1} {"value" c, "id" 2} {"value" c,
> > "id" 3} {"value" b, "id" 4} {"value" a, "id" 5})
> >
> > When using ".indexOf" I can't manage to work with values that repeats.
> Any
> > tips?
> >
> > thank. Christian.
> >
> > --
> > 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 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 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 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

Reply via email to