-
-
Notifications
You must be signed in to change notification settings - Fork 713
/
utils.cljc
32 lines (29 loc) · 964 Bytes
/
utils.cljc
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
(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)))
(defn apply-kw
"Like apply, but f takes keyword arguments and the last argument is
not a seq but a map with the arguments for f"
[f & args]
{:pre [(map? (last args))]}
(apply f (apply concat
(butlast args) (last args))))