On Thu, Dec 9, 2010 at 8:43 PM, Steven E. Harris wrote:
> Ken Wesson 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 Haskell's function o
Ken Wesson 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 Haskell's function of the same name. It's not obvious to me that
mapping a function over a
On Dec 7, 5:50 am, Sean Devlin 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 subscribed to the Googl
If you use (empty m) rather than {} it will also work for other types.
On Dec 7, 5:45 am, Ken Wesson 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, :b 8}
>
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 wrote:
> While on the topic, I'd like to raise a naming issue.
>
> The 'mapmap'
On Tue, Dec 7, 2010 at 3:31 AM, Tobias Raeder
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) (valf v)])))
> 550ms
>
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 inp
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. B
Ahh apply does it again! I saw how the code be simplified, but just tonight
learned how apply can be used in situations like this.
--
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
On Tue, Dec 7, 2010 at 12:04 AM, Alex Baranosky
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 %3 ) {:a 1 :b 2} {:a 3
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
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
c 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 that.
>>
>> Alex
>>
>> --
>> You received this message beca
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
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 moder
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 p
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'
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
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 t
Avital Oliver 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.
I agree, bu
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 efficient,
Florian Ebeling
> >
> > > 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]
> > > (redu
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 wr
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
On Thu, Dec 17, 2009 at 12:16 PM, Konrad Hinsen
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] [k (f v)])))
Are
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 alr
(assoc! m k (f v))) (transient {}) m))
>
> HTH,
>
> --
> Laurent
>
> 2009/12/17 C. Florian Ebeling
>
> > I was just wondering how a #'map for maps could be done most
> > succinctly. Came up with this:
>
> > (defn mapmap
> > "Map values
On Dec 17, 9:37 am, "C. Florian Ebeling"
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?
> 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
[k v]]
(assoc! m k (f v))) (transient {}) m))
HTH,
--
Laurent
2009/12/17 C. Florian Ebeling
> 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.&qu
e:
> 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 proba
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 yo
33 matches
Mail list logo