diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/data/coll/array.lux | 88 |
1 files changed, 44 insertions, 44 deletions
diff --git a/stdlib/source/lux/data/coll/array.lux b/stdlib/source/lux/data/coll/array.lux index ac15bfe9d..b45cab136 100644 --- a/stdlib/source/lux/data/coll/array.lux +++ b/stdlib/source/lux/data/coll/array.lux @@ -1,4 +1,4 @@ -(;module: +(.module: lux (lux (control [monoid #+ Monoid] [functor #+ Functor] @@ -38,29 +38,29 @@ dest-array (list/fold (function [offset target] (case (read (n/+ offset src-start) src-array) - #;None + #.None target - (#;Some value) + (#.Some value) (write (n/+ offset dest-start) value target))) dest-array - (list;n/range +0 (n/dec length))))) + (list.n/range +0 (n/dec length))))) (def: #export (occupied array) - {#;doc "Finds out how many cells in an array are occupied."} + {#.doc "Finds out how many cells in an array are occupied."} (All [a] (-> (Array a) Nat)) (list/fold (function [idx count] (case (read idx array) - #;None + #.None count - (#;Some _) + (#.Some _) (n/inc count))) +0 - (list;indices (size array)))) + (list.indices (size array)))) (def: #export (vacant array) - {#;doc "Finds out how many cells in an array are vacant."} + {#.doc "Finds out how many cells in an array are vacant."} (All [a] (-> (Array a) Nat)) (n/- (occupied array) (size array))) @@ -70,26 +70,26 @@ (list/fold (: (-> Nat (Array ($ +0)) (Array ($ +0))) (function [idx xs'] (case (read idx xs) - #;None + #.None xs' - (#;Some x) + (#.Some x) (if (p x) xs' (delete idx xs'))))) xs - (list;indices (size xs))) + (list.indices (size xs))) ## (list/fold (function [idx xs'] ## (case (read idx xs) - ## #;None + ## #.None ## xs' - ## (#;Some x) + ## (#.Some x) ## (if (p x) ## xs' ## (delete idx xs')))) ## xs - ## (list;indices (size xs))) + ## (list.indices (size xs))) ) (def: #export (find p xs) @@ -99,50 +99,50 @@ (loop [idx +0] (if (n/< arr-size idx) (case (read idx xs) - #;None + #.None (recur (n/inc idx)) - (#;Some x) + (#.Some x) (if (p x) - (#;Some x) + (#.Some x) (recur (n/inc idx)))) - #;None)))) + #.None)))) (def: #export (find+ p xs) - {#;doc "Just like 'find', but with access to the index of each value."} + {#.doc "Just like 'find', but with access to the index of each value."} (All [a] (-> (-> Nat a Bool) (Array a) (Maybe [Nat a]))) (let [arr-size (size xs)] (loop [idx +0] (if (n/< arr-size idx) (case (read idx xs) - #;None + #.None (recur (n/inc idx)) - (#;Some x) + (#.Some x) (if (p idx x) - (#;Some [idx x]) + (#.Some [idx x]) (recur (n/inc idx)))) - #;None)))) + #.None)))) (def: #export (clone xs) (All [a] (-> (Array a) (Array a))) (let [arr-size (size xs)] (list/fold (function [idx ys] (case (read idx xs) - #;None + #.None ys - (#;Some x) + (#.Some x) (write idx x ys))) (new arr-size) - (list;indices arr-size)))) + (list.indices arr-size)))) (def: #export (from-list xs) (All [a] (-> (List a) (Array a))) - (product;right (list/fold (function [x [idx arr]] + (product.right (list/fold (function [x [idx arr]] [(n/inc idx) (write idx x arr)]) - [+0 (new (list;size xs))] + [+0 (new (list.size xs))] xs))) (def: underflow Nat (n/dec +0)) @@ -150,15 +150,15 @@ (def: #export (to-list array) (All [a] (-> (Array a) (List a))) (loop [idx (n/dec (size array)) - output #;Nil] + output #.Nil] (if (n/= underflow idx) output (recur (n/dec idx) (case (read idx array) - (#;Some head) - (#;Cons head output) + (#.Some head) + (#.Cons head output) - #;None + #.None output))))) (struct: #export (Eq<Array> Eq<a>) @@ -170,16 +170,16 @@ (list/fold (function [idx prev] (and prev (case [(read idx xs) (read idx ys)] - [#;None #;None] + [#.None #.None] true - [(#;Some x) (#;Some y)] + [(#.Some x) (#.Some y)] (:: Eq<a> = x y) _ false))) true - (list;n/range +0 (n/dec sxs))))) + (list.n/range +0 (n/dec sxs))))) )) (struct: #export Monoid<Array> (All [a] @@ -201,22 +201,22 @@ (list/fold (: (-> Nat (Array ($ +1)) (Array ($ +1))) (function [idx mb] (case (read idx ma) - #;None + #.None mb - (#;Some x) + (#.Some x) (write idx (f x) mb)))) (new arr-size) - (list;n/range +0 (n/dec arr-size))) + (list.n/range +0 (n/dec arr-size))) ## (list/fold (function [idx mb] ## (case (read idx ma) - ## #;None + ## #.None ## mb - ## (#;Some x) + ## (#.Some x) ## (write idx (f x) mb))) ## (new arr-size) - ## (list;n/range +0 (n/dec arr-size))) + ## (list.n/range +0 (n/dec arr-size))) )))) (struct: #export _ (Fold Array) @@ -226,9 +226,9 @@ idx +0] (if (n/< arr-size idx) (case (read idx xs) - #;None + #.None (recur so-far (n/inc idx)) - (#;Some value) + (#.Some value) (recur (f value so-far) (n/inc idx))) so-far))))) |