Last active
August 29, 2015 14:26
-
-
Save ptaoussanis/2556c56d93bde4af0415 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 oget | |
"Like `aget` for JS objects, Ref. https://goo.gl/eze8hY. Unlike `aget`, | |
returns nil for missing keys instead of throwing." | |
([o k] (when o (gobj/get o k nil))) | |
([o k1 k2] (when-let [o (oget o k1)] (gobj/get o k2 nil))) ; Optimized common case | |
([o k1 k2 & ks] (when-let [o (oget o k1 k2)] (apply oget o ks)))) ; Can also lean on optimized 2-case |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment