diff options
Diffstat (limited to 'stdlib/source/lux/data/coll/array.lux')
-rw-r--r-- | stdlib/source/lux/data/coll/array.lux | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/stdlib/source/lux/data/coll/array.lux b/stdlib/source/lux/data/coll/array.lux index 855c35d8e..dd3a94553 100644 --- a/stdlib/source/lux/data/coll/array.lux +++ b/stdlib/source/lux/data/coll/array.lux @@ -45,7 +45,7 @@ (#.Some value) (write (n/+ offset dest-start) value target))) dest-array - (list.n/range +0 (n/dec length))))) + (list.n/range +0 (dec length))))) (def: #export (occupied array) {#.doc "Finds out how many cells in an array are occupied."} @@ -56,7 +56,7 @@ count (#.Some _) - (n/inc count))) + (inc count))) +0 (list.indices (size array)))) @@ -88,12 +88,12 @@ (if (n/< arr-size idx) (case (read idx xs) #.None - (recur (n/inc idx)) + (recur (inc idx)) (#.Some x) (if (p x) (#.Some x) - (recur (n/inc idx)))) + (recur (inc idx)))) #.None)))) (def: #export (find+ p xs) @@ -105,12 +105,12 @@ (if (n/< arr-size idx) (case (read idx xs) #.None - (recur (n/inc idx)) + (recur (inc idx)) (#.Some x) (if (p idx x) (#.Some [idx x]) - (recur (n/inc idx)))) + (recur (inc idx)))) #.None)))) (def: #export (clone xs) @@ -129,19 +129,19 @@ (def: #export (from-list xs) (All [a] (-> (List a) (Array a))) (product.right (list/fold (function (_ x [idx arr]) - [(n/inc idx) (write idx x arr)]) + [(inc idx) (write idx x arr)]) [+0 (new (list.size xs))] xs))) -(def: underflow Nat (n/dec +0)) +(def: underflow Nat (dec +0)) (def: #export (to-list array) (All [a] (-> (Array a) (List a))) - (loop [idx (n/dec (size array)) + (loop [idx (dec (size array)) output #.Nil] (if (n/= underflow idx) output - (recur (n/dec idx) + (recur (dec idx) (case (read idx array) (#.Some head) (#.Cons head output) @@ -167,11 +167,10 @@ _ false))) true - (list.n/range +0 (n/dec sxs))))) + (list.n/range +0 (dec sxs))))) )) -(struct: #export Monoid<Array> (All [a] - (Monoid (Array a))) +(struct: #export Monoid<Array> (All [a] (Monoid (Array a))) (def: identity (new +0)) (def: (compose xs ys) @@ -194,7 +193,7 @@ (#.Some x) (write idx (f x) mb))) (new arr-size) - (list.n/range +0 (n/dec arr-size))) + (list.n/range +0 (dec arr-size))) )))) (struct: #export _ (Fold Array) @@ -205,8 +204,8 @@ (if (n/< arr-size idx) (case (read idx xs) #.None - (recur so-far (n/inc idx)) + (recur so-far (inc idx)) (#.Some value) - (recur (f value so-far) (n/inc idx))) + (recur (f value so-far) (inc idx))) so-far))))) |