weavejester / medley

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

Add transducer arity to functions operating on maps #33

Closed yuhan0 closed 6 months ago

yuhan0 commented 5 years ago

See discussion in #12

Add a 1-argument arity to the following functions, which returns a transducer consuming and producing a sequence of [key value] map-entry pairs, and can be used to construct a map using (into {} xform coll).

The second commit refactors out repeated code into a private completing-rf function, if needed this can be omitted or squashed into the previous one.

yuhan0 commented 5 years ago

Tests for the new transducer arities haven't been written yet, is it alright to simply duplicate the test cases in a (into {}) form? eg.

(deftest test-map-keys
  (is (= (map f coll)
         expected)))

=> 

(deftest test-map-keys
  (testing "maps"
    (is (= (m/map-keys f coll)
           expected)))
  (testing "transducers"
    (is (= (into {} (m/map-keys f) coll)
           expected))))
yuhan0 commented 5 years ago

I pushed the requested changes and added simple "duplicate" tests of the existing ones (they all pass), let me know if you'd like the commits to be squashed in a particular way.

weavejester commented 6 months ago

I've considered this, but on reflection I don't think I want the map functions in Medley to support transducers.