diff options
Diffstat (limited to 'src/utils.clj')
| -rwxr-xr-x | src/utils.clj | 17 |
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)))) |
