diff --git a/src/datomish/util.cljc b/src/datomish/util.cljc index 779408ab..36099535 100644 --- a/src/datomish/util.cljc +++ b/src/datomish/util.cljc @@ -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))))