summaryrefslogtreecommitdiff
path: root/src/utils.clj
diff options
context:
space:
mode:
authorScott Ostler <scottbot9000@gmail.com>2011-02-13 20:06:24 -0500
committerScott Ostler <scottbot9000@gmail.com>2011-02-13 20:06:24 -0500
commitf2f8cddb8b23fd3b932fccf1e40ced258ed71bb9 (patch)
tree67ddc657c07cff7808ab5de7cea8a95b6eb31784 /src/utils.clj
parentd59f06da8e56c511dfd573cce2d8382dc043def1 (diff)
added sort-by-index-in, removed old index-of funcs
Diffstat (limited to 'src/utils.clj')
-rwxr-xr-xsrc/utils.clj17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/utils.clj b/src/utils.clj
index 25814f9..84f185a 100755
--- a/src/utils.clj
+++ b/src/utils.clj
@@ -446,10 +446,15 @@
{ :result result :time (System/currentTimeMillis)})
result)))))
-;; From Programming Clojure by Stuart Halloway
+;; Misc index/sorting funcs
-(defn index-filter [pred coll]
- (for [[idx elt] (indexed coll) :when (pred elt)] idx))
-
-(defn index-of [pred coll]
- (first (index-filter pred coll)))
+(defn sort-by-index-in
+ ([c1 c2] (sort-by-index-in c1 c2 nil nil))
+ ([c1 c2 f1] (sort-by-index-in c1 c2 f1 nil))
+ ([c1 c2 f1 f2]
+ (let [c2-map (zipmap (if f2 (map f2 c2) c2)
+ (range (count c2)))
+ sort-func (if f1
+ #(get c2-map (f1 %))
+ #(get c2-map %))]
+ (sort-by sort-func c1))))