specter

Latest version: 1.1.3
roklenarcic 2018-07-17T08:28:46.000045Z

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

roklenarcic 2018-07-17T08:28:52.000360Z

How do I solve this?

roklenarcic 2018-07-17T08:29:28.000354Z

ALL (collect FIRST) LAST?

roklenarcic 2018-07-17T08:38:08.000025Z

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

pepe 2018-07-17T08:55:51.000100Z

@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

roklenarcic 2018-07-17T09:36:00.000015Z

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

pepe 2018-07-17T10:27:46.000069Z

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

roklenarcic 2018-07-17T13:28:52.000141Z

that's about the same amount of code

nathanmarz 2018-07-17T13:30:02.000178Z

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

roklenarcic 2018-07-17T13:32:50.000420Z

Already solved it

roklenarcic 2018-07-17T13:33:34.000423Z

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

roklenarcic 2018-07-17T13:34:13.000173Z

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