summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTimothy Pratley <timothypratley@gmail.com>2010-01-30 14:32:43 +1100
committerStuart Halloway <stu@thinkrelevance.com>2010-06-07 10:03:25 -0400
commitc19ce8145053578763ac3bef4de9d8c3c44e1b11 (patch)
treed778ca2813dbbe677665a44ff988d3ad787aba64 /src
parent59ecee6a6f037612b3b1ed2d939f5e0017f2dd11 (diff)
get-in support for default #256
Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
Diffstat (limited to 'src')
-rw-r--r--src/clj/clojure/core.clj13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj
index 11800ead..ca615435 100644
--- a/src/clj/clojure/core.clj
+++ b/src/clj/clojure/core.clj
@@ -4907,10 +4907,15 @@
;;;;;;;;;;;;; nested associative ops ;;;;;;;;;;;
(defn get-in
- "returns the value in a nested associative structure, where ks is a sequence of keys"
- {:added "1.0"}
- [m ks]
- (reduce get m ks))
+ "Returns the value in a nested associative structure,
+ where ks is a sequence of ke(ys. Returns nil if the key is not present,
+ or the not-found value if supplied."
+ ([m ks]
+ (reduce get m ks))
+ ([m ks not-found]
+ (if (seq ks)
+ (get (reduce get m (butlast ks)) (last ks) not-found)
+ m)))
(defn assoc-in
"Associates a value in a nested associative structure, where ks is a