Re: grouping and mapping

2016-08-14 Thread Steve Miner
Sorry, I got the semantics of the grouping-fn wrong. My code assumes that the key is always first in the elements and my grouping is more like a merging-fn. > On Aug 14, 2016, at 2:53 PM, miner wrote: > > If your data elements are essentially map-entries (key-value pairs), I'd use > reduce.

Re: grouping and mapping

2016-08-14 Thread miner
If your data elements are essentially map-entries (key-value pairs), I'd use reduce. Maybe something like this would work for you... (defn mapping-group-by [grouping-fn mapping-fn coll] (reduce (fn [res [k v]] (update res k grouping-fn (mapping-fn v))) {} coll)) (def foos

Re: grouping and mapping

2016-08-13 Thread Simon Belak
Another option (and shameless self promotion) is the rollup family of functions in https://github.com/sbelak/huri Your case would be: (rollup first identity second foos) => {:a ("foo" "baz"), :b ("bar")} On Friday, August 12, 2016 at 7:10:37 PM UTC+2, Erik Assum wrote: > > I’ve been working on

Re: grouping and mapping

2016-08-12 Thread Christophe Grand
I have a collection of transducers that I use in such cases: (require '[net.cgrand.xforms :as x] '[clojure.string :as str]) (into {} (x/by-key (comp (map str/upper-case) (x/into []))) ;=> [[:a "foo"] [:b "bar"] [:a "baz"]]) On Fri, Aug 12, 2016 at 7:14 PM, Moe Aboulkheir wrote: > As far a

Re: grouping and mapping

2016-08-12 Thread Moe Aboulkheir
As far as already existing, (grouped-map first (comp str/upper-case second) ...) or similar, with https://github.com/plumatic/plumbing/blob/master/src/plumbing/core.cljx#L164 Take care, Moe On Fri, Aug 12, 2016 at 6:10 PM, Erik Assum wrote: > I’ve been working on a new project in java 8 at a ne