Skip to content

Commit 8cdf827

Browse files
committed
- fix infinite loop
- add tests
1 parent 533b383 commit 8cdf827

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

List.ark

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@
260260
(mut _index 0)
261261
(mut _output [])
262262
(mut continue true)
263-
(while continue
263+
(while (and (< _index (len _L)) continue)
264264
(if (_f (@ _L _index))
265265
{
266266
(set _output (append _output (@ _L _index)))

tests/list-tests.ark

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@
5151
(set tests (assert-eq (list:take a 1) [1] "take" tests))
5252
(set tests (assert-eq (list:take a 100) a "take" tests))
5353

54+
(set tests (assert-eq (list:takeWhile a (fun (c) (< c 0))) [] "takeWhile" tests))
55+
(set tests (assert-eq (list:takeWhile a (fun (c) (< c 2))) [1] "takeWhile" tests))
56+
(set tests (assert-eq (list:takeWhile a (fun (c) (< c 3))) [1 2] "takeWhile" tests))
57+
(set tests (assert-eq (list:takeWhile a (fun (c) (< c 5))) [1 2 3] "takeWhile" tests))
58+
5459
(set tests (assert-eq (list:unzip zipped) [[1 2 3 4] [5 6 7 8]] "unzip" tests))
5560
(set tests (assert-eq (list:unzip []) [[] []] "unzip" tests))
5661

0 commit comments

Comments
 (0)