Skip to content

Instantly share code, notes, and snippets.

@fogus
Created Jan 21, 2011
Embed
What would you like to do?
(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