mirror of
https://github.com/janet-lang/janet
synced 2025-10-19 01:37:40 +00:00
Fix nil error on drop-until fn
This commit is contained in:
@@ -703,7 +703,9 @@
|
|||||||
the predicate, and abort on first failure. Returns a new array."
|
the predicate, and abort on first failure. Returns a new array."
|
||||||
[pred ind]
|
[pred ind]
|
||||||
(def i (find-index pred ind))
|
(def i (find-index pred ind))
|
||||||
(array/slice ind i))
|
(if i
|
||||||
|
(array/slice ind i)
|
||||||
|
@[]))
|
||||||
|
|
||||||
(defn drop-while
|
(defn drop-while
|
||||||
"Same as (drop-until (complement pred) ind)."
|
"Same as (drop-until (complement pred) ind)."
|
||||||
|
@@ -80,4 +80,12 @@
|
|||||||
(assert-no-error "break 3" (for i 0 10 (if (> i 8) (break i))))
|
(assert-no-error "break 3" (for i 0 10 (if (> i 8) (break i))))
|
||||||
(assert-no-error "break 4" ((fn [i] (if (> i 8) (break i))) 100))
|
(assert-no-error "break 4" ((fn [i] (if (> i 8) (break i))) 100))
|
||||||
|
|
||||||
|
# drop-until
|
||||||
|
|
||||||
|
(assert (deep= (drop-until pos? @[]) @[]) "drop-until 1")
|
||||||
|
(assert (deep= (drop-until pos? @[1 2 3]) @[1 2 3]) "drop-until 2")
|
||||||
|
(assert (deep= (drop-until pos? @[-1 -2 -3]) @[]) "drop-until 3")
|
||||||
|
(assert (deep= (drop-until pos? @[-1 -2 3]) @[3]) "drop-until 4")
|
||||||
|
(assert (deep= (drop-until pos? @[-1 1 -2]) @[1 -2]) "drop-until 5")
|
||||||
|
|
||||||
(end-suite)
|
(end-suite)
|
||||||
|
Reference in New Issue
Block a user