Skip to content

Instantly share code, notes, and snippets.

@rotaliator
Last active June 13, 2019 21:34
Show Gist options
  • Save rotaliator/be569cb1b0b461f86caf4669a39d1856 to your computer and use it in GitHub Desktop.
Save rotaliator/be569cb1b0b461f86caf4669a39d1856 to your computer and use it in GitHub Desktop.
(defn separate-by [f coll]
"Separates coll into two groups by predicate f
example:
=> (separate-by odd? (range 20))
[[1 3 5 7 9 11 13 15 17 19] [0 2 4 6 8 10 12 14 16 18]]
"
(let [groups (group-by (comp boolean f) coll)]
[(groups true) (groups false)]))
;; or
(defn separate-by [f coll]
((juxt filter remove) f coll))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment