aboutsummaryrefslogtreecommitdiff
path: root/src/clojure/contrib/greatest_least.clj
diff options
context:
space:
mode:
Diffstat (limited to 'src/clojure/contrib/greatest_least.clj')
-rw-r--r--src/clojure/contrib/greatest_least.clj65
1 files changed, 0 insertions, 65 deletions
diff --git a/src/clojure/contrib/greatest_least.clj b/src/clojure/contrib/greatest_least.clj
deleted file mode 100644
index 79e41813..00000000
--- a/src/clojure/contrib/greatest_least.clj
+++ /dev/null
@@ -1,65 +0,0 @@
-(ns
- #^{:author "Vincent Foley",
- :doc "Various functions for finding greatest and least values in a collection"}
- clojure.contrib.greatest-least)
-
-(defn- boundary
- [cmp-fn f & args]
- (when args
- (reduce (fn [a b] (if (cmp-fn (compare (f b) (f a)))
- b
- a)) args)))
-
-(defn greatest-by
- "Return the argument for which f yields the greatest value."
- [f & args]
- (apply boundary pos? f args))
-
-(defn greatest
- "Return the greatest argument."
- [& args]
- (apply greatest-by identity args))
-
-(defn least-by
- "Return the argument for which f yields the smallest value."
- [f & args]
- (apply boundary neg? f args))
-
-(defn least
- "Return the smallest element."
- [& args]
- (apply least-by identity args))
-
-
-(defn- boundary-all
- [cmp-fn f & args]
- (when args
- (reduce (fn [a b]
- (if (nil? a)
- (cons b nil)
- (let [x (compare (f b) (f (first a)))]
- (cond (zero? x) (cons b a)
- (cmp-fn x) (cons b nil)
- :else a))))
- nil
- args)))
-
-(defn all-greatest-by
- "Return all the elements for which f yields the greatest value."
- [f & args]
- (apply boundary-all pos? f args))
-
-(defn all-greatest
- "Returns all the greatest elements."
- [& args]
- (apply all-greatest-by identity args))
-
-(defn all-least-by
- "Return all the elements for which f yields the least value."
- [f & args]
- (apply boundary-all neg? f args))
-
-(defn all-least
- "Returns all the least elements."
- [& args]
- (apply all-least-by identity args))