Details
-
Type:
Enhancement
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Completed
-
Affects Version/s: None
-
Fix Version/s: Release 1.3
-
Component/s: None
-
Labels:None
-
Patch:Code and Test
-
Approval:Ok
Description
Per the discussion at http://groups.google.com/group/clojure-dev/browse_frm/thread/899349c6a9b526e0
There is a general interest in a set of functions named any/every-pred that take a set of predicates and return a function that applies logical AND/OR to the application of each of its args. The naive implementations would be:
(defn every-pred [& preds] (fn [& args] (every? #(every? % args) preds))) ((every-pred pos? even?) 1 3 5 7 9) ;=> false ((every-pred pos? odd?) 1 3 5 7 9) ;=> true (defn any-pred [& preds] (fn [& args] (some #(some % args) preds))) ((any-pred pos? even?) -1 2 3 4 5 6) ;=> true
However, these implementations fall down in the following ways and should be corrected before inclusion to clojure.core:
1) The functions returned by each do not adhere to the same results as (and) and (or) given no arguments.
2) They and their returned functions assume varargs in every call. should be variadically unrolled in much the same way as juxt and comp. A longer term solution would be to implement them in terms of a macro that performs the unrolling automatically, but that is "extra-credit".
3) They should be tested in other_functions.clj
Added a patch containing the variadic unwound versions of every-pred and any-pred and tests for each.