fix end, last, beginning, and first to work on nil

This commit is contained in:
Nathan Marz 2016-06-08 14:42:24 -04:00
parent 9045e13386
commit 98343784bf
3 changed files with 15 additions and 0 deletions

View file

@ -5,6 +5,7 @@
* Added `selected-any?` operation that returns true if any element is navigated to.
* Huge performance improvements to `select`, `select-one`, `select-first`, and `select-one!`
* Added META navigator (thanks @aengelberg)
* Bug fix: END, BEGINNING, FIRST, and LAST now work properly on nil
## 0.11.1
* More efficient inline caching for Clojure version, benchmarks show inline caching within 5% of manually precompiled code for all cases

View file

@ -479,6 +479,12 @@
(prepend-all [structure elements]))
(extend-protocol AddExtremes
nil
(append-all [_ elements]
elements)
(prepend-all [_ elements]
elements)
#+clj clojure.lang.PersistentVector #+cljs cljs.core/PersistentVector
(append-all [structure elements]
(reduce conj structure elements))
@ -567,6 +573,9 @@
(extend-protocol FastEmpty
nil
(fast-empty? [_] true)
#+clj clojure.lang.IPersistentVector #+cljs cljs.core/PersistentVector
(fast-empty? [v]
(= 0 (vec-count v)))

View file

@ -1191,3 +1191,8 @@
(first (select s/META (with-meta v meta-map)))
(first (select s/META (setval s/META meta-map v))))))
(deftest beginning-end-on-nil
(is (= [2 3] (setval s/END [2 3] nil) (setval s/BEGINNING [2 3] nil)))
(is (nil? (setval s/FIRST :a nil)))
)