Skip to content

Instantly share code, notes, and snippets.

@kliph
Created December 11, 2013 17:33
Show Gist options
  • Save kliph/7914833 to your computer and use it in GitHub Desktop.
Save kliph/7914833 to your computer and use it in GitHub Desktop.
A little Clojure function to filter a list by some predicate and divide it into those elements for which the predicate is true and those elements for which the predicate is not true.
(defn filter-by [pred coll]
(let [grouped-map (group-by pred coll)
{true-list true
false-list false} grouped-map]
(merge [true-list false-list])))
(= '[[1 3 5 7 9] [0 2 4 6 8]] (filter-by odd? (range 10)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment