diff options
author | Stuart Sierra <mail@stuartsierra.com> | 2011-01-20 08:56:43 -0500 |
---|---|---|
committer | Stuart Halloway <stu@thinkrelevance.com> | 2011-01-28 10:12:48 -0500 |
commit | 13d9404b5227f3b9e8f86371d211be890e5302a9 (patch) | |
tree | 1d52be5945c4654f5d77a3d5c220d9385a47c4af | |
parent | f79efe17adbcca1991d66598f027fd61f36e1f70 (diff) |
keys and vals check for instanceof Map
Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
-rw-r--r-- | src/jvm/clojure/lang/RT.java | 14 | ||||
-rw-r--r-- | test/clojure/test_clojure/data_structures.clj | 22 |
2 files changed, 24 insertions, 12 deletions
diff --git a/src/jvm/clojure/lang/RT.java b/src/jvm/clojure/lang/RT.java index aad678c7..6017aaf0 100644 --- a/src/jvm/clojure/lang/RT.java +++ b/src/jvm/clojure/lang/RT.java @@ -470,11 +470,21 @@ static ISeq seqFrom(Object coll){ } static public ISeq keys(Object coll){ - return APersistentMap.KeySeq.create(seq(coll)); + if(coll == null) + return null; + else if (coll instanceof Map) + return APersistentMap.KeySeq.create(seq(coll)); + else + throw new IllegalArgumentException("Don't know how to get keys from: " + coll.getClass().getName()); } static public ISeq vals(Object coll){ - return APersistentMap.ValSeq.create(seq(coll)); + if(coll == null) + return null; + else if (coll instanceof Map) + return APersistentMap.ValSeq.create(seq(coll)); + else + throw new IllegalArgumentException("Don't know how to get vals from: " + coll.getClass().getName()); } static public IPersistentMap meta(Object x){ diff --git a/test/clojure/test_clojure/data_structures.clj b/test/clojure/test_clojure/data_structures.clj index 7679b2b6..08d0ee38 100644 --- a/test/clojure/test_clojure/data_structures.clj +++ b/test/clojure/test_clojure/data_structures.clj @@ -440,11 +440,12 @@ (deftest test-keys - (are [x y] (= x y) ; other than map data structures - (keys ()) nil - (keys []) nil - (keys #{}) nil - (keys "") nil ) + (are [x] (thrown? Exception (keys x)) + ;; other than map data structures + () + [] + #{} + "") (are [x y] (= x y) ; (class {:a 1}) => clojure.lang.PersistentArrayMap @@ -464,11 +465,12 @@ (deftest test-vals - (are [x y] (= x y) ; other than map data structures - (vals ()) nil - (vals []) nil - (vals #{}) nil - (vals "") nil ) + (are [x] (thrown? Exception (vals x)) + ;; other than map data structures + () + [] + #{} + "") (are [x y] (= x y) ; (class {:a 1}) => clojure.lang.PersistentArrayMap |