Skip to content

Instantly share code, notes, and snippets.

@mwmitchell
Created September 13, 2011 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mwmitchell/1214682 to your computer and use it in GitHub Desktop.
Save mwmitchell/1214682 to your computer and use it in GitHub Desktop.
rate-filter.clj
(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