diff options
-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 |