Merge release Beta 1 into stable #21
1 changed files with 20 additions and 19 deletions
|
@ -1,25 +1,6 @@
|
||||||
(ns rss-thread-watch.utils
|
(ns rss-thread-watch.utils
|
||||||
"Util functions"
|
"Util functions"
|
||||||
(:gen-class))
|
(:gen-class))
|
||||||
;; ===== Generic functions ====
|
|
||||||
|
|
||||||
(defn indices
|
|
||||||
;; https://stackoverflow.com/questions/8641305/find-index-of-an-element-matching-a-predicate-in-clojure
|
|
||||||
"Returns indexes of elements passing predicate"
|
|
||||||
[pred coll]
|
|
||||||
(keep-indexed #(when (pred %2) %1) coll))
|
|
||||||
|
|
||||||
(defn map-deep-merge-missing
|
|
||||||
"Merges two maps but only keys missing from first map"
|
|
||||||
[m1 m2]
|
|
||||||
(into m1
|
|
||||||
(for [k (keys m2)]
|
|
||||||
(let [val1 (get m1 k)
|
|
||||||
val2 (get m2 k)]
|
|
||||||
(if (and (map? val1)
|
|
||||||
(map? val2))
|
|
||||||
{k (map-deep-merge-missing val1 val2)}
|
|
||||||
{k (nil?-else val2 val1)})))))
|
|
||||||
|
|
||||||
;; ===== Macros =====
|
;; ===== Macros =====
|
||||||
(defmacro nil?-else
|
(defmacro nil?-else
|
||||||
|
@ -51,3 +32,23 @@
|
||||||
(if result#
|
(if result#
|
||||||
~x
|
~x
|
||||||
result#)))
|
result#)))
|
||||||
|
|
||||||
|
;; ===== Generic functions ====
|
||||||
|
|
||||||
|
(defn indices
|
||||||
|
;; https://stackoverflow.com/questions/8641305/find-index-of-an-element-matching-a-predicate-in-clojure
|
||||||
|
"Returns indexes of elements passing predicate"
|
||||||
|
[pred coll]
|
||||||
|
(keep-indexed #(when (pred %2) %1) coll))
|
||||||
|
|
||||||
|
(defn map-deep-merge-missing
|
||||||
|
"Merges two maps but only keys missing from first map"
|
||||||
|
[m1 m2]
|
||||||
|
(into m1
|
||||||
|
(for [k (keys m2)]
|
||||||
|
(let [val1 (get m1 k)
|
||||||
|
val2 (get m2 k)]
|
||||||
|
(if (and (map? val1)
|
||||||
|
(map? val2))
|
||||||
|
{k (map-deep-merge-missing val1 val2)}
|
||||||
|
{k (nil?-else val2 val1)})))))
|
||||||
|
|
Loading…
Reference in a new issue