Skip to content

Instantly share code, notes, and snippets.

@mwmitchell
Created March 27, 2012 15:37
Show Gist options
  • Save mwmitchell/2217129 to your computer and use it in GitHub Desktop.
Save mwmitchell/2217129 to your computer and use it in GitHub Desktop.
list filtering
(let [candidates [{:udicode 1} {:udicode 2} {:udicode 3} {:udicode 4} {:udicode 1} {:udicode 9} {:udicode 20}]
result (atom #{})
filters [#(not (@result %))
#(< (:udicode %) 10)]
include? (fn [h]
(if (every? #(% h) filters)
(swap! result conj h)))]
(take 7 (filter include? candidates)))
;; using juxt and reduce for applying the filters:
(reduce #(and %1 %2) ((apply juxt [nil? keyword? (constantly true)]) nil))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment