Skip to content

Instantly share code, notes, and snippets.

@fogus
Created January 21, 2011 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fogus/790187 to your computer and use it in GitHub Desktop.
Save fogus/790187 to your computer and use it in GitHub Desktop.
(defn conjoin [& preds]
"Given a bunch of predicates, returns a function that is the logical AND
of said functions against a bunch of values."
(fn [& args] (every? #(every? % args) preds)))
((conjoin pos? even?) 1 3 5 7 9)
;=> false
((conjoin pos? odd?) 1 3 5 7 9)
;=> true
((conjoin pos? even?) 2 4 6 8 10)
;=> true
(apply (conjoin identity) [true false true])
;=> false
(defn disjoin [& preds]
"Given a bunch of predicates, returns a function that is the logical OR
of said functions against a bunch of values."
(fn [& args] (some #(some % args) preds)))
((disjoin pos? even?) -1 -3)
;=> nil
((disjoin pos? even?) -1 2 3 4 5 6)
;=> true
(apply (disjoin identity) [true false true])
;=> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment