25 lines
714 B
Clojure
25 lines
714 B
Clojure
(ns re-frame.utils
|
|
(:require
|
|
[re-frame.loggers :refer [console]]))
|
|
|
|
(defn dissoc-in
|
|
"Dissociates an entry from a nested associative structure returning a new
|
|
nested structure. keys is a sequence of keys. Any empty maps that result
|
|
will not be present in the new structure.
|
|
The key thing is that 'm' remains identical? to istelf if the path was never present"
|
|
[m [k & ks :as keys]]
|
|
(if ks
|
|
(if-let [nextmap (get m k)]
|
|
(let [newmap (dissoc-in nextmap ks)]
|
|
(if (seq newmap)
|
|
(assoc m k newmap)
|
|
(dissoc m k)))
|
|
m)
|
|
(dissoc m k)))
|
|
|
|
(defn first-in-vector
|
|
[v]
|
|
(if (vector? v)
|
|
(first v)
|
|
(console :error "re-frame: expected a vector, but got:" v)))
|