🐛 Fix safe-subvec 2-arity rejecting start=0

The guard used (> start 0) instead of (>= start 0), so
(safe-subvec v 0) returned nil instead of the full vector.
This commit is contained in:
Andrey Antukh 2026-04-14 22:58:13 +00:00 committed by Belén Albeza
parent 176edadb6f
commit 2e97f01838
2 changed files with 3 additions and 1 deletions

View File

@ -1146,7 +1146,7 @@
"Wrapper around subvec so it doesn't throw an exception but returns nil instead" "Wrapper around subvec so it doesn't throw an exception but returns nil instead"
([v start] ([v start]
(when (and (some? v) (when (and (some? v)
(> start 0) (< start (count v))) (>= start 0) (< start (count v)))
(subvec v start))) (subvec v start)))
([v start end] ([v start end]
(when (some? v) (when (some? v)

View File

@ -325,6 +325,8 @@
(t/is (= [2 3] (d/safe-subvec [1 2 3 4] 1 3))) (t/is (= [2 3] (d/safe-subvec [1 2 3 4] 1 3)))
;; single arg — from index to end ;; single arg — from index to end
(t/is (= [2 3 4] (d/safe-subvec [1 2 3 4] 1))) (t/is (= [2 3 4] (d/safe-subvec [1 2 3 4] 1)))
;; start=0 returns the full vector
(t/is (= [1 2 3 4] (d/safe-subvec [1 2 3 4] 0)))
;; out-of-range returns nil ;; out-of-range returns nil
(t/is (nil? (d/safe-subvec [1 2 3] 5))) (t/is (nil? (d/safe-subvec [1 2 3] 5)))
(t/is (nil? (d/safe-subvec [1 2 3] 0 5))) (t/is (nil? (d/safe-subvec [1 2 3] 0 5)))