Created
March 22, 2020 15:36
-
-
Save dominem/84a79fb07b96ba4ff72c2ffe6aa5f89d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn my-assoc-in | |
[m [k & ks] v] | |
(assoc m k | |
(reduce (fn [v-in k-in] (assoc {} k-in v-in)) | |
v | |
(reverse ks)))) | |
(comment | |
(my-assoc-in {} [:a] 1) | |
;; => {:a 1} | |
(my-assoc-in {:a 1} [:b] 2) | |
;; => {:a 1, :b 2} | |
(my-assoc-in {:a 1} [:a] 2) | |
;; => {:a 2} | |
(my-assoc-in {} [:a :b :c] 4) | |
;; => {:a {:b {:c 4}}} | |
(my-assoc-in {:a {:b 3}} [:a :b] {:c 123}) | |
;; => {:a {:b {:c 123}}} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment