Created
December 11, 2013 17:33
-
-
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.
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 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