Created
September 13, 2011 18:51
-
-
Save mwmitchell/1214682 to your computer and use it in GitHub Desktop.
rate-filter.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn remove-out-of-range-rates [rates min-rate max-rate] | |
(let [out-of-range? #(not (<= min-rate (:total_rate %) max-rate)) | |
reducer (fn [m {:keys [rates] :as item}] | |
(let [frates (remove out-of-range? rates)] | |
(if-not (empty? frates) | |
(conj m (assoc item :rates frates)) | |
m)))] | |
(reduce reducer [] rates))) | |
(remove-out-of-range-rates [{:rates [{:total_rate 10} {:total_rate 15}]} | |
{:rates [{:total_rate 12} {:total_rate 9}]}] | |
10 15) | |
;; => | |
;; [{:rates ({:total_rate 10} {:total_rate 15})} {:rates ({:total_rate 12})}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment