Fork me on GitHub
#specter
<
2018-07-17
>
roklenarcic08:07:46

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

roklenarcic08:07:52

How do I solve this?

roklenarcic08:07:28

ALL (collect FIRST) LAST?

roklenarcic08:07:08

This case comes up all the time. I want to decide which path to take based on key, but I want to transform value.

pepe08:07:51

@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

roklenarcic09:07:00

I know that one, but I hoped for a shorter solution.

pepe10:07:46

Ok. Have you looked at if-path cond-path?

roklenarcic13:07:52

that's about the same amount of code

nathanmarz13:07:02

@roklenarcic it will be easier to help you if you show the input/output of the transformation you want to do

roklenarcic13:07:50

Already solved it

roklenarcic13:07:34

(transform [ALL (collect-one FIRST) LAST ALL] map-fn result-of-group-by)

roklenarcic13:07:13

allows me to have map-fn of two arguments that processes lists in group-by map-of-vectors