Skip to content

Instantly share code, notes, and snippets.

@postspectacular
Created May 1, 2016 12:31
Show Gist options
  • Save postspectacular/cdde5f63a8d9a1142b829b5a74be2317 to your computer and use it in GitHub Desktop.
Save postspectacular/cdde5f63a8d9a1142b829b5a74be2317 to your computer and use it in GitHub Desktop.
get-in macro version
(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