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.
Ok. Have you looked at if-path cond-path?
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