Define conj-in, a conjing variant of assoc-in.
This commit is contained in:
parent
5a8dbace4a
commit
69348eb0b4
1 changed files with 12 additions and 0 deletions
|
@ -17,3 +17,15 @@
|
|||
(str/starts-with? (name x) "?"))
|
||||
(keyword (subs (name x) 1))
|
||||
(raise (str x " is not a Datalog var."))))
|
||||
|
||||
(defn conj-in
|
||||
"Associates a value into a sequence in a nested associative structure, where
|
||||
ks is a sequence of keys and v is the new value, and returns a new nested
|
||||
structure.
|
||||
If any levels do not exist, hash-maps will be created. If the destination
|
||||
sequence does not exist, a new one is created."
|
||||
{:static true}
|
||||
[m [k & ks] v]
|
||||
(if ks
|
||||
(assoc m k (conj-in (get m k) ks v))
|
||||
(assoc m k (conj (get m k) v))))
|
||||
|
|
Loading…
Reference in a new issue