On Thu, Dec 9, 2010 at 8:43 PM, Steven E. Harris s...@panix.com wrote:
Ken Wesson kwess...@gmail.com writes:
and to encapsulate as a function:
(defn fmap [f m]
(into {}
(for [[k v] m]
[k (f v)])))
Here, fmap is a poor choice of name, if it's meant to be a reference
to
While on the topic, I'd like to raise a naming issue.
The 'mapmap' function seems to be a recurring theme (see, e.g.,
http://tech.puredanger.com/2010/09/24/meet-my-little-friend-mapmap/)
and many Clojure projects include one -- Incanter comes to mind. My
project used to, too. But we found out
Just checking performance versus the version i have been using i
noticed quite a difference
For 10 runs over a small 10 key/value map
(defn fmap [keyf valf m]
(into {}
(for [[k v] m]
[(keyf k) (valf v)])))
550ms
(defn fmap2 [keyf valf m]
(- (fn [inputmap [k v]]
(assoc
On Tue, Dec 7, 2010 at 3:31 AM, Tobias Raeder
tobias.rae...@googlemail.com wrote:
Just checking performance versus the version i have been using i
noticed quite a difference
For 10 runs over a small 10 key/value map
(defn fmap [keyf valf m]
(into {}
(for [[k v] m]
[(keyf k)
This is a solved problem. The trick is to use a higher-higher order
function...
http://fulldisclojure.blogspot.com/2010/01/12-fn-proposal-same-multisame.html
On Dec 7, 7:38 am, Daniel Janus nath...@gmail.com wrote:
While on the topic, I'd like to raise a naming issue.
The 'mapmap' function
If you use (empty m) rather than {} it will also work for other types.
On Dec 7, 5:45 am, Ken Wesson kwess...@gmail.com wrote:
This is also very easy to implement:
(into {}
(for [[k v] the-map]
[k (f v)]))
e.g.
user= (into {}
(for [[k v] {:a 3 :b 7}]
[k (inc v)]))
{:a 4,
On Dec 7, 5:50 am, Sean Devlin francoisdev...@gmail.com wrote:
This is a solved problem. The trick is to use a higher-higher order
function...
http://fulldisclojure.blogspot.com/2010/01/12-fn-proposal-same-multis...
Why not call it unseq?
--
You received this message because you are
Do the standard libraries contain a function to map a function over a map?
(mapmap inc {:a 1 :b 2}) = (2, 3)
--
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
Oops. I meant:
(mapmap inc {:a 1 :b 2}) = { :a 2 :b 3)
Sorry about that.
Alex
--
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
Hi Alex,
(clojure.contrib.generic.functor/fmap inc {:a 1 :b 2}) = {:a 2 :b 3}
The above is probably what you want.
HTH
Sunil.
On Tue, Dec 7, 2010 at 9:26 AM, Alex Baranosky
alexander.barano...@gmail.com wrote:
Oops. I meant:
(mapmap inc {:a 1 :b 2}) = { :a 2 :b 3)
Sorry about
alexander.barano...@gmail.com wrote:
Oops. I meant:
(mapmap inc {:a 1 :b 2}) = { :a 2 :b 3)
Sorry about that.
Alex
--
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
This is also very easy to implement:
(into {}
(for [[k v] the-map]
[k (f v)]))
e.g.
user= (into {}
(for [[k v] {:a 3 :b 7}]
[k (inc v)]))
{:a 4, :b 8}
user=
and to encapsulate as a function:
(defn fmap [f m]
(into {}
(for [[k v] m]
[k (f v)])))
--
You received this
I think it will be fun to come up with a solution that will work with n
maps:
(defn multi-fmap [f maps]
...)
i.e.
(multi-fmap #(+ %1 %1 %2 ) {:a 1 :b 2} {:a 3 :b 4}) = {:a 5 :b 8}
(multi-fmap #(+ %1 %2 %3 ) {:a 1 :b 2} {:a 3 :b 4} {:a 5 :b 6}) = {:a 9 :b
12}
--
You received this message
On Tue, Dec 7, 2010 at 12:04 AM, Alex Baranosky
alexander.barano...@gmail.com wrote:
I think it will be fun to come up with a solution that will work with n
maps:
(defn multi-fmap [f maps]
...)
i.e.
(multi-fmap #(+ %1 %1 %2 ) {:a 1 :b 2} {:a 3 :b 4}) = {:a 5 :b 8}
(multi-fmap #(+ %1 %2
I've been using a number of similar functions in my own coding. This
was my approach.
(defn seq2map
Constructs a map from a sequence by applying keyvalfn to each
element of the sequence. keyvalfn should return a pair [key val]
to be added to the map for each input sequence element.
On 18 Dec 2009, at 15:03, Sean Devlin wrote:
The last entry is the most relevant to a map-utils library. Check out
the visitor stuff:
http://groups.google.com/group/clojure-dev/msg/6c1bbce17cafdf52
The idea is to take your generic functor application idea and put it
on steroids. I'm
On 17 Dec 2009, at 20:26, Sean Devlin wrote:
Konrad,
I am working on a different proposal on the dev list:
http://groups.google.com/group/clojure-dev/browse_thread/thread/9a518c853bfbba8b#
This is a more in depth version of these functions for maps. I'd love
to have you contribute to the
Konrad,
Yeah, there are discussions of two libs there. The idea is that most
of the fn in this thread will be used for table-utils.
The last entry is the most relevant to a map-utils library. Check out
the visitor stuff:
http://groups.google.com/group/clojure-dev/msg/6c1bbce17cafdf52
The idea
I was just wondering how a #'map for maps could be done most
succinctly. Came up with this:
(defn mapmap
Map values of map m using function f.
[f m]
(reduce (fn [m [k v]]
(assoc m k (f v))) {} m))
But there is probably a more straightforward way. What do you use?
Florian
wrote:
I was just wondering how a #'map for maps could be done most
succinctly. Came up with this:
(defn mapmap
Map values of map m using function f.
[f m]
(reduce (fn [m [k v]]
(assoc m k (f v))) {} m))
But there is probably a more straightforward way. What do you use
]]
(assoc! m k (f v))) (transient {}) m))
HTH,
--
Laurent
2009/12/17 C. Florian Ebeling florian.ebel...@gmail.com
I was just wondering how a #'map for maps could be done most
succinctly. Came up with this:
(defn mapmap
Map values of map m using function f.
[f m]
(reduce (fn [m
AFAIK, such a function is still not in clojure core because it's not clear
to Rich whether f should have one argument (the value), or 2 arguments (key
+ value).
That is a good question. But I thought if the key makes a difference,
then one could use standard map and rely on map's collection
On Dec 17, 9:37 am, C. Florian Ebeling florian.ebel...@gmail.com
wrote:
(defn mapmap
Map values of map m using function f.
[f m]
(reduce (fn [m [k v]]
(assoc m k (f v))) {} m))
But there is probably a more straightforward way. What do you use?
I do that exactly, but I
))) (transient {}) m))
HTH,
--
Laurent
2009/12/17 C. Florian Ebeling florian.ebel...@gmail.com
I was just wondering how a #'map for maps could be done most
succinctly. Came up with this:
(defn mapmap
Map values of map m using function f.
[f m]
(reduce (fn [m [k v
On 17 Dec 2009, at 15:44, Sean Devlin wrote:
1. I'd call it map-vals (as opposed to map-keys)
2. Slight change in the body
(defn map-vals [f coll]
(into {} (map (juxt key (comp f val)) coll))
There is talk of getting something like this into contrib. Stay
tuned :)
There's already
On Thu, Dec 17, 2009 at 12:16 PM, Konrad Hinsen
konrad.hin...@fastmail.net wrote:
On 17 Dec 2009, at 15:44, Sean Devlin wrote:
(defn map-vals [f coll]
(into {} (map (juxt key (comp f val)) coll))
vs:
(defmethod fmap clojure.lang.IPersistentMap
[f m]
(into (empty m) (for [[k v] m]
Konrad,
I am working on a different proposal on the dev list:
http://groups.google.com/group/clojure-dev/browse_thread/thread/9a518c853bfbba8b#
This is a more in depth version of these functions for maps. I'd love
to have you contribute to the discussion here.
Sean
On Dec 17, 12:16 pm, Konrad
Depends if you need a closure. There are times I do 2D mappings, and
I have to write something like
(map (partail map #(do-work %)) coll).
Or I have to compose my mapping operations.
for is awesome when you need some of the other built-ins, like :while
Sean
On Dec 17, 12:39 pm, Erik Price
with this:
(defn mapmap
Map values of map m using function f.
[f m]
(reduce (fn [m [k v]]
(assoc m k (f v))) {} m))
But there is probably a more straightforward way. What do you use?
Florian
--
Florian Ebeling
florian.ebel...@gmail.com
--
You received
Erik,
My experience is that you should only use filter/map if you either have a
pre-existing function or you want to use a _very_ short closure (using #()).
For any other case the code becomes unmanageable and then I feel that using
for is the wiser choice.
I hope that they are just as
Avital Oliver avi...@thewe.net writes:
My experience is that you should only use filter/map if you either have a
pre-existing function or you want to use a _very_ short closure (using #()).
For any other case the code becomes unmanageable and then I feel that using
for
is the wiser choice.
31 matches
Mail list logo