Skip to content

Commit e6fce5a

Browse files
committed
CLJ-1872 Extend empty? to counted? colls that arent seqable, such as transients
1 parent 1e8fb8f commit e6fce5a

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

src/clj/clojure/core.clj

+10-7
Original file line numberDiff line numberDiff line change
@@ -6244,13 +6244,6 @@ fails, attempts to require sym's namespace and retries."
62446244
([m k f x y z & more]
62456245
(assoc m k (apply f (get m k) x y z more))))
62466246

6247-
(defn empty?
6248-
"Returns true if coll has no items - same as (not (seq coll)).
6249-
Please use the idiom (seq x) rather than (not (empty? x))"
6250-
{:added "1.0"
6251-
:static true}
6252-
[coll] (not (seq coll)))
6253-
62546247
(defn coll?
62556248
"Returns true if x implements IPersistentCollection"
62566249
{:added "1.0"
@@ -6306,6 +6299,16 @@ fails, attempts to require sym's namespace and retries."
63066299
:static true}
63076300
[coll] (instance? clojure.lang.Counted coll))
63086301

6302+
(defn empty?
6303+
"Returns true if coll has no items. To check the emptiness of a seq,
6304+
please use the idiom (seq x) rather than (not (empty? x))"
6305+
{:added "1.0"
6306+
:static true}
6307+
[coll]
6308+
(if (counted? coll)
6309+
(zero? (count coll))
6310+
(not (seq coll))))
6311+
63096312
(defn reversible?
63106313
"Returns true if coll implements Reversible"
63116314
{:added "1.0"

test/clojure/test_clojure/sequences.clj

+8-2
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,10 @@
11361136
{}
11371137
#{}
11381138
""
1139-
(into-array []) )
1139+
(into-array [])
1140+
(transient [])
1141+
(transient #{})
1142+
(transient {}))
11401143

11411144
(are [x] (not (empty? x))
11421145
'(1 2)
@@ -1145,7 +1148,10 @@
11451148
{:a 1 :b 2}
11461149
#{1 2}
11471150
"abc"
1148-
(into-array [1 2]) ))
1151+
(into-array [1 2])
1152+
(transient [1])
1153+
(transient #{1})
1154+
(transient {1 2})))
11491155

11501156

11511157
(deftest test-every?

0 commit comments

Comments
 (0)