Awesome. Thanks Konrad.
On Mar 23, 4:11 am, Konrad Hinsen wrote:
> On 22.03.2009, at 21:10, Jon Nadal wrote:
>
>
>
> > I often need to map a function over the values of a map while
> > preserving keys--something like:
> ...
> > Is there a more concise way to do this in Clojure? If not, is this
On Mon, 23 Mar 2009 at 20:10, David Sletten wrote:
> I think Mark was referring to the call to 'keys'. But apparently
> Clojure doesn't need to traverse the map to generate the keys?
The call to keys just creates a seq. There's no traversal until you consume it.
> Not sure what you mean here.
On Mar 23, 2009, at 5:24 AM, Jeff Valk wrote:
>
> On Mon, 23 Mar 2009 at 03:29, Mark Engelberg wrote:
>
>> But it traverses m twice, which is likely to be less efficient.
>
> I wondered about this too, and actually no.
I think Mark was referring to the call to 'keys'. But apparently
Clojure d
On Mon, 23 Mar 2009 at 10:48, Konrad Hinsen wrote:
> It is already in clojure.contrib, with exactly that implementation,
> and for exactly that reason:
Well I'm glad we agree then. :-) And thanks for the pointer.
-Jeff
--~--~-~--~~~---~--~~
You received this m
On Mar 23, 2009, at 16:36, Jeff Valk wrote:
>> I prefer the into version which allows to write a mapmap that
>> preserves the
>> map type (eg sorted or hash):
>>
>> (defn mapmap [f m]
>> (into (empty m) (for [[k v] m] [k (f v)])))
>
> Agreed. If it were in contrib, this would make most sense.
On Mon, 23 Mar 2009 at 07:57, Christophe Grand wrote:
> I prefer the into version which allows to write a mapmap that preserves the
> map type (eg sorted or hash):
>
> (defn mapmap [f m]
> (into (empty m) (for [[k v] m] [k (f v)])))
Agreed. If it were in contrib, this would make most sense.
On Mon, 23 Mar 2009 at 03:29, Mark Engelberg wrote:
> But it traverses m twice, which is likely to be less efficient.
I wondered about this too, and actually no. Zipmap is efficient. It constructs
its return map in a single loop from two lazy seqs. Performance is practically
identical to the "
On Mar 23, 2009, at 14:26, Mark Volkmann wrote:
>> That leaves the question whether there is still any need for the
>> clojure.lang.ISeq implementation. At the moment it is used for lists,
>> but that is not particularly consistent. I guess I will remove it.
>
> Maybe you should keep it to suppor
On Mon, Mar 23, 2009 at 7:04 AM, Konrad Hinsen
wrote:
>
> On Mar 23, 2009, at 12:15, Mark Volkmann wrote:
>
>>> Look at clojure.contrib.generic.functor/fmap. It does what you need
>>> for maps, for all the other Clojure collections (where it works like
>>> map except that its return value is a co
I prefer the into version which allows to write a mapmap that preserves the
map type (eg sorted or hash):
(defn mapmap [f m]
(into (empty m) (for [[k v] m] [k (f v)])))
Christophe
On Mon, Mar 23, 2009 at 7:53 AM, Jeff Valk wrote:
>
> On Sun, 22 Mar 2009 at 23:27, Jeff Valk wrote:
>
> > Ah, go
On Mar 23, 2009, at 12:15, Mark Volkmann wrote:
>> Look at clojure.contrib.generic.functor/fmap. It does what you need
>> for maps, for all the other Clojure collections (where it works like
>> map except that its return value is a collection of the same type as
>> the input value), and you can i
On Mon, Mar 23, 2009 at 3:11 AM, Konrad Hinsen
wrote:
>
> On 22.03.2009, at 21:10, Jon Nadal wrote:
>
>> I often need to map a function over the values of a map while
>> preserving keys--something like:
> ...
>> Is there a more concise way to do this in Clojure? If not, is this
>> something that
On Sun, Mar 22, 2009 at 11:53 PM, Jeff Valk wrote:
> For the record, I think the original approach is the most clear. And it's
> actually shorter.
>
> (defn mapmap [f m]
> (zipmap (keys m) (map f (vals m
But it traverses m twice, which is likely to be less efficient.
--~--~-~--~--
On 22.03.2009, at 21:10, Jon Nadal wrote:
> I often need to map a function over the values of a map while
> preserving keys--something like:
...
> Is there a more concise way to do this in Clojure? If not, is this
> something that might be worth putting in the contrib?
Look at clojure.contrib.g
On Sun, 22 Mar 2009 at 23:27, Jeff Valk wrote:
> Ah, golf... :-)
>
> (defn mapmap [f m]
> (into {} (for [[k v] m] [k (f v)])))
For the record, I think the original approach is the most clear. And it's
actually shorter.
(defn mapmap [f m]
(zipmap (keys m) (map f (vals m
--~--~---
ooh for
On Sun, Mar 22, 2009 at 9:27 PM, Jeff Valk wrote:
>
> On 22 March 2009 23:14, Timothy Pratley wrote:
>
>> Golf time!
>>
>> (defn mapmap [f m]
>> (into {} (map (fn [[x y]] [x (f y)]) m)))
>
> Ah, golf... :-)
>
> (defn mapmap [f m]
> (into {} (for [[k v] m] [k (f v)])))
>
> >
>
--
On 22 March 2009 23:14, Timothy Pratley wrote:
> Golf time!
>
> (defn mapmap [f m]
> (into {} (map (fn [[x y]] [x (f y)]) m)))
Ah, golf... :-)
(defn mapmap [f m]
(into {} (for [[k v] m] [k (f v)])))
--~--~-~--~~~---~--~~
You received this message becaus
Golf time!
(defn mapmap [f m]
(into {} (map (fn [[x y]] [x (f y)]) m)))
On Mar 23, 2:51 pm, Kevin Downey wrote:
> (defn mapmap [fn m]
> (into {} (map #(vector (first %) (fn (second %))) m)))
--~--~-~--~~~---~--~~
You received this message because you ar
(defn mapmap [fn m]
(into {} (map #(vector (first %) (fn (second %))) m)))
On Sun, Mar 22, 2009 at 1:10 PM, Jon Nadal wrote:
>
> I often need to map a function over the values of a map while
> preserving keys--something like:
>
> [code]
> (defn mapmap [fn m]
> (let [k (keys m)
> v (m
I often need to map a function over the values of a map while
preserving keys--something like:
[code]
(defn mapmap [fn m]
(let [k (keys m)
v (map fn (vals m))]
(zipmap k v)))
(mapmap inc {:a 0, :b 1})
[/code]
Is there a more concise way to do this in Clojure? If not, is this
some
20 matches
Mail list logo