Skip to content

Commit b766dae

Browse files
mfikesswannodette
authored andcommitted
CLJS-1531: realized? for lazy-seq
- Add support for IPending to LazySeq. - Change param from d to x in places (no longer just delay) - Unit test via lazy-seq built with cons cells
1 parent 20ab0d1 commit b766dae

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -650,9 +650,9 @@
650650

651651
(defprotocol IPending
652652
"Protocol for types which can have a deferred realization. Currently only
653-
implemented by Delay."
654-
(^boolean -realized? [d]
655-
"Returns true if a value for d has been produced, false otherwise."))
653+
implemented by Delay and LazySeq."
654+
(^boolean -realized? [x]
655+
"Returns true if a value for x has been produced, false otherwise."))
656656

657657
(defprotocol IWatchable
658658
"Protocol for types that can be watched. Currently only implemented by Atom."
@@ -3014,6 +3014,10 @@ reduces them without incurring seq initialization"
30143014
(set! fn nil)
30153015
s)))
30163016

3017+
IPending
3018+
(-realized? [x]
3019+
(not fn))
3020+
30173021
IWithMeta
30183022
(-with-meta [coll meta] (LazySeq. meta fn s __hash))
30193023

@@ -9195,7 +9199,7 @@ reduces them without incurring seq initialization"
91959199
value)
91969200

91979201
IPending
9198-
(-realized? [d]
9202+
(-realized? [x]
91999203
(not f)))
92009204

92019205
(defn ^boolean delay?
@@ -9211,8 +9215,8 @@ reduces them without incurring seq initialization"
92119215

92129216
(defn ^boolean realized?
92139217
"Returns true if a value has been produced for a delay or lazy sequence."
9214-
[d]
9215-
(-realized? d))
9218+
[x]
9219+
(-realized? x))
92169220

92179221
(defn- preserving-reduced
92189222
[rf]

src/test/cljs/cljs/core_test.cljs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,19 @@
16391639
(is (= '(2 3) (next (range 1 4))))
16401640
))
16411641

1642+
(deftest test-lazy-seq-realized?
1643+
(testing "Testing LazySeq IPending"
1644+
(let [xs (lazy-seq
1645+
(cons 1
1646+
(lazy-seq
1647+
(cons 2
1648+
(lazy-seq (cons 3 nil))))))]
1649+
(is (not (realized? xs)))
1650+
(is (not (realized? (rest xs))))
1651+
(is (realized? xs))
1652+
(is (not (realized? (nthrest xs 2))))
1653+
(is (realized? (rest xs))))))
1654+
16421655
(deftest test-chunked
16431656
(let [r (range 64)
16441657
v (into [] r)]

0 commit comments

Comments
 (0)