weavejester / medley

A lightweight library of useful Clojure functions
Eclipse Public License 1.0
870 stars 67 forks source link

Variadic version of map-vals #35

Closed yuhan0 closed 5 years ago

yuhan0 commented 5 years ago

Would it be a good idea for map-vals to accept multiple collections with a variadic function, just like regular map and mapcat?

(map-vals min
  {:x 1 :y 4 :z 20}
  {:x 3 :y -6 :z 15}
  {:x 0 :y 8 :z 16})
;; => {:x 0, :y -6, :z 15}

(map-vals concat
  {:xs [1 2 3] :ys [4 5 6]}
  {:xs [3 2 1] :ys [7 8 9]})
;; => {:xs (1 2 3 3 2 1), :ys (4 5 6 7 8 9)}

It would break symmetry with map-keys and map-kv, which don't seem to have an intuitive analogue for being applied to multiple colls.

Also I'm not sure how missing or extra keys should be handled:

(map-vals + {:foo 10} {:foo 5 :bar 6})
;; => {:foo 15 :bar ??}
weavejester commented 5 years ago

It's not a bad idea. I assume it work work the same way as map for missing keys, so it would ignore keys that aren't common throughout.

(map + [10] [5 6])
;; => (15)

(map-vals + {:foo 10} {:foo 5 :bar 6})
;; => {:foo 15}