Welcome again.
Here's another way. Not sure if it's any more or less efficient, but it's
the way my brain works.
=> (defn map-hashmap [coll f]
(apply hash-map (interleave coll (map f coll))))
#'user/map-hashmap
=> (map-hashmap [1 2 3] #(+ % 3))
{1 4, 2 5, 3 6}
On Mon, Aug 24, 2009 at 2:18 AM, Stephen C. Gilardi <[email protected]>wrote:
>
> On Aug 23, 2009, at 8:21 PM, Stan Dyck wrote:
>
> I'm still new to this so bear with me.
>>
>
> Welcome.
>
> I'm trying to apply a function to a seq-able thing to produce a hashmap.
>> So for instance say the function is (inc 3).
>> I'd like to write a function that does
>>
>> [1 2 3] --> {1 4, 2 5, 3 6}
>>
>> Can someone help me?
>>
>
> Here's one way:
>
> user=> (into {} (for [i [1 2 3]] [i (+ 3 i)]))
> {1 4, 2 5, 3 6}
>
> --Steve
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---