data.deque icon indicating copy to clipboard operation
data.deque copied to clipboard

Bug with adding and removing `nil`

Open DrSplinter opened this issue 4 years ago • 3 comments

There is a problem with the following:

(require '[data.deque :as dq])
(assert (= (list 2 nil)
           (-> (dq/deque)
               (dq/add-first nil)
               (dq/add-first nil)
               (dq/add-first 2)
               dq/remove-last
               seq)))

Interesting is the fact that if we add-last and then remove-first it works correctly.

DrSplinter avatar Dec 06 '21 06:12 DrSplinter

When removing an element, the finger tree may shrink by checking returning nil. It seems nils in the example is causing the wrong behavior. (In general, inserting nil into a collection is not recommended.)

I'll make a PR not to use nil as a marker. Thanks.

namenu avatar Dec 07 '21 02:12 namenu

Oh, OK then. I'll use some keyword like :clojure.spec.alpha/invalid keyword used in spec :-)

Thank you too

(should I close this Issue?)

DrSplinter avatar Dec 07 '21 13:12 DrSplinter

No, it's an obvious bug of data.deque so let's keep this open. 😃

namenu avatar Dec 08 '21 09:12 namenu