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
;; My implementation of Clojure update-in function | |
(defn my-update-in | |
[m ks f & args] | |
(let [sorted-keys (reverse ks)] | |
(loop [curr-key (first sorted-keys) | |
rem-keys (rest sorted-keys) | |
curr-map (get-in m (reverse rem-keys)) | |
acc-val (assoc curr-map curr-key (apply f (get-in m ks) args))] | |
(if (empty? rem-keys) |
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
;; The core function assoc-in | |
(defn my-assoc-in | |
[m [& ks] v] | |
(let [sorted-keys (reverse ks)] | |
(loop [curr-key (first sorted-keys) | |
rem-keys (rest sorted-keys) | |
curr-map (get-in m (reverse rem-keys)) | |
acc-val (assoc curr-map curr-key v)] | |
(if (empty? rem-keys) | |
acc-val |
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
;; The clojure comp cre function | |
;; Recursive | |
(defn my-comp | |
([] my-comp) | |
([f] f) | |
([f & fs] | |
(fn [& args] | |
(f (apply (apply my-comp fs) args))))) |