-
-
Notifications
You must be signed in to change notification settings - Fork 46
/
core.clj
33 lines (26 loc) · 862 Bytes
/
core.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
(ns polylith.clj.core.util.core)
(defn find-first [predicate sequence]
(first (filter predicate sequence)))
(defn ordered-map
"Takes a vector of key/value pairs and returns
an ordered map, except entries that has nil as a value"
[keyvals]
(let [pairs (filter #(-> % second nil? not)
(partition 2 keyvals))]
(apply array-map
(mapcat identity pairs))))
(defn- key-as-string [[lib version]]
[(str lib) version])
(defn stringify-and-sort-map [m]
(apply array-map
(mapcat identity
(sort (map key-as-string m)))))
(defn sort-map [m]
(when m
(apply array-map
(mapcat identity
(sort (map identity m))))))
(defn- def-val [amap key]
(list 'def key (list (keyword key) amap)))
(defmacro def-map [amap keys]
(conj (map #(def-val amap %) keys) 'do))