diff options
-rw-r--r-- | src/clj/clojure/boot.clj | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/clj/clojure/boot.clj b/src/clj/clojure/boot.clj index 6e3f878a..ea68acf5 100644 --- a/src/clj/clojure/boot.clj +++ b/src/clj/clojure/boot.clj @@ -3196,3 +3196,29 @@ (printf "(clojure/load-resources \"%s\")\n" path) (flush)) (.loadResourceScript clojure.lang.RT (.substring path 1))))) + +;;;;;;;;;;;;; nested associative ops ;;;;;;;;;;; + +(defn get-in + "returns the value in a nested associative structure, where ks is a sequence of keys" + [m ks] + (reduce get m ks)) + +(defn assoc-in + "Associates a value 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." + [m [k & ks] v] + (if ks + (assoc m k (assoc-in (get m k) ks v)) + (assoc m k v))) + +(defn update-in + "'Updates' a value in a nested associative structure, where ks is a + sequence of keys and f is a function that will take the old value + and return the new value, and returns a new nested structure. + If any levels do not exist, hash-maps will be created." + ([m [k & ks] f] + (if ks + (assoc m k (update-in (get m k) ks f)) + (assoc m k (f (get m k)))))) |