summaryrefslogtreecommitdiff
path: root/src/utils.clj
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.clj')
-rwxr-xr-xsrc/utils.clj20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/utils.clj b/src/utils.clj
index ee64789..84f185a 100755
--- a/src/utils.clj
+++ b/src/utils.clj
@@ -269,8 +269,7 @@
(insert-values table cols values)))
(defn assert-update
- ([res ok err] (if (not (= (first res) 1)) err ok))
- ([res] (assert-update res true false)))
+ ([res] (= (first res) 1)))
(defn sql-array [type arr]
(with-connection *db*
@@ -447,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))))