Created
January 21, 2011 18:53
-
-
Save fogus/790187 to your computer and use it in GitHub Desktop.
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 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