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.
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
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
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
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