-
-
Save gmp26/0c74fcf449bbcd1ad1c3bf36ca067d2f to your computer and use it in GitHub Desktop.
get-in macro version
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
(defmacro get-in* | |
"Macro version of clojure.core/get-in without not-found fallback" | |
[root path] | |
(loop [root root, path path] | |
(if path | |
(recur `(get ~root ~(first path)) (next path)) | |
root))) | |
(macroexpand-1 '(get-in* [[1 2 3] [3 4 [5 6 7 8]]] [1 2 3])) | |
;; (clojure.core/get (clojure.core/get (clojure.core/get [[1 2 3] [3 4 [5 6 7 8]]] 1) 2) 3) | |
(get-in* [[1 2 3] [3 4 [5 6 7 8]]] [1 2 3]) | |
;; 8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment