clojure

Filter into two different collections


(let [ truthys (filter #(filter-func %) coll)
       falsys (filter #(not filter-func %) coll)]

This code traverves coll twice and applys filter-func twice to each element. I was wondering, is there a way to filter coll into both truthys and falsys in just one go?


Solution

  • (let [{truhys true, falsys false}
          (group-by filter-func coll)]
      ...)