This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-07-17
Channels
- # beginners (42)
- # cider (1)
- # cljs-dev (20)
- # clojure (73)
- # clojure-italy (8)
- # clojure-nl (53)
- # clojure-spec (11)
- # clojure-uk (88)
- # clojurescript (170)
- # clojutre (6)
- # core-async (26)
- # css (2)
- # cursive (13)
- # data-science (10)
- # datomic (15)
- # editors (3)
- # figwheel (28)
- # figwheel-main (67)
- # fulcro (57)
- # graphql (2)
- # immutant (2)
- # jobs (1)
- # jvm (4)
- # lein-figwheel (3)
- # leiningen (1)
- # off-topic (5)
- # pedestal (28)
- # re-frame (86)
- # reagent (18)
- # reitit (8)
- # ring (3)
- # ring-swagger (2)
- # shadow-cljs (78)
- # spacemacs (10)
- # specter (12)
- # tools-deps (32)
- # vim (3)
I often have to transform map's values but I need value's key to do the transformation, so MAP-VALS
doesn't cut it
How do I solve this?
ALL (collect FIRST) LAST
?
This case comes up all the time. I want to decide which path to take based on key, but I want to transform value.
@roklenarcic ALL returns [k v] vector on map so (transform ALL (fn [[k v]] (if (= k :a) [k (inc v)] [k (dec v)])) {:a 1 :b 2})
works
I know that one, but I hoped for a shorter solution.
that's about the same amount of code
@roklenarcic it will be easier to help you if you show the input/output of the transformation you want to do
Already solved it
(transform [ALL (collect-one FIRST) LAST ALL] map-fn result-of-group-by)
allows me to have map-fn of two arguments that processes lists in group-by map-of-vectors