Skip to content

Instantly share code, notes, and snippets.

@gmp26
Forked from postspectacular/get-in.clj
Last active August 4, 2017 13:52
Show Gist options
  • Save gmp26/0c74fcf449bbcd1ad1c3bf36ca067d2f to your computer and use it in GitHub Desktop.
Save gmp26/0c74fcf449bbcd1ad1c3bf36ca067d2f 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