weavejester / medley

A lightweight library of useful Clojure functions
Eclipse Public License 1.0
865 stars 66 forks source link

Added filter-vals #1

Closed henrygarner closed 11 years ago

henrygarner commented 11 years ago

Thanks for the performance tip-off. I also prefer it stylistically.

I've squashed the commits into one.

weavejester commented 11 years ago

This seems like a good addition, as I recall several times when I'd have found such a function useful.

However, if you write it as:

(defn filter-vals [pred coll]
  (persistent! (reduce-kv #(if (pred %3) (assoc! %1 %2 %3) %1)
                          (transient (empty coll))
                          coll)))

It's about 6 times faster (according to some quick Criterium benchmarks).

weavejester commented 11 years ago

Could you squash your commits, then I'll merge the changes in.