aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/data/coll/array.lux24
1 files changed, 13 insertions, 11 deletions
diff --git a/stdlib/source/lux/data/coll/array.lux b/stdlib/source/lux/data/coll/array.lux
index 833da6230..a4a3aa903 100644
--- a/stdlib/source/lux/data/coll/array.lux
+++ b/stdlib/source/lux/data/coll/array.lux
@@ -133,19 +133,21 @@
[+0 (new (list;size xs))]
xs)))
+(def: underflow Nat (n.dec +0))
+
(def: #export (to-list array)
(All [a] (-> (Array a) (List a)))
- (let [_size (size array)]
- (product;right (list/fold (function [_ [idx tail]]
- (case (read idx array)
- (#;Some head)
- [(n.dec idx) (#;Cons head tail)]
-
- #;None
- [(n.dec idx) tail]))
- [(n.dec _size) #;Nil]
- (list;repeat _size [])
- ))))
+ (loop [idx (n.dec (size array))
+ output #;Nil]
+ (if (n.= underflow idx)
+ output
+ (recur (n.dec idx)
+ (case (read idx array)
+ (#;Some head)
+ (#;Cons head output)
+
+ #;None
+ output)))))
(struct: #export (Eq<Array> Eq<a>)
(All [a] (-> (Eq a) (Eq (Array a))))