Skip to content

Instantly share code, notes, and snippets.

@amalloy
Forked from mwmitchell/gist:1214682
Created September 13, 2011 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amalloy/1214703 to your computer and use it in GitHub Desktop.
Save amalloy/1214703 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))]
(for [{r :rates :as item} rates
:let [allowed (remove out-of-range? r)]
:when (seq allowed)]
(assoc item :rates allowed))))
(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