aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--stdlib/source/lux/data/coll/list.lux17
-rw-r--r--stdlib/test/test/lux/control/region.lux2
-rw-r--r--stdlib/test/test/lux/data/coll/list.lux33
3 files changed, 34 insertions, 18 deletions
diff --git a/stdlib/source/lux/data/coll/list.lux b/stdlib/source/lux/data/coll/list.lux
index b9b743b2c..f6c19dcb9 100644
--- a/stdlib/source/lux/data/coll/list.lux
+++ b/stdlib/source/lux/data/coll/list.lux
@@ -303,16 +303,21 @@
xs')]
($_ compose (sort < pre) (list x) (sort < post)))))
-(do-template [<name> <type> <comp> <inc>]
+(do-template [<name> <type> <lt> <inc> <gt> <dec>]
[(def: #export (<name> from to)
{#.doc "Generates an inclusive interval of values [from, to]."}
(-> <type> <type> (List <type>))
- (if (<comp> to from)
- (list& from (<name> (<inc> from) to))
- (list)))]
+ (cond (<lt> to from)
+ (list& from (<name> (<inc> from) to))
- [i/range Int i/<= i/inc]
- [n/range Nat n/<= n/inc]
+ (<gt> to from)
+ (list& from (<name> (<dec> from) to))
+
+ ## (= to from)
+ (list from)))]
+
+ [i/range Int i/< i/inc i/> i/dec]
+ [n/range Nat n/< n/inc n/> n/dec]
)
(def: #export (empty? xs)
diff --git a/stdlib/test/test/lux/control/region.lux b/stdlib/test/test/lux/control/region.lux
index a7a577ab5..fc1eb7edf 100644
--- a/stdlib/test/test/lux/control/region.lux
+++ b/stdlib/test/test/lux/control/region.lux
@@ -26,7 +26,7 @@
(context: "Regions."
(<| (times +100)
(do @
- [expected-clean-ups (|> r.nat (:: @ map (n/% +100)))]
+ [expected-clean-ups (|> r.nat (:: @ map (|>> (n/% +100) (n/max +1))))]
($_ seq
(test "Clean-up functions are always run when region execution is done."
(thread.run
diff --git a/stdlib/test/test/lux/data/coll/list.lux b/stdlib/test/test/lux/data/coll/list.lux
index 729519823..578b652da 100644
--- a/stdlib/test/test/lux/data/coll/list.lux
+++ b/stdlib/test/test/lux/data/coll/list.lux
@@ -132,6 +132,8 @@
other-size bounded-size
other-sample (r.list other-size r.nat)
separator r.nat
+ from (|> r.nat (:: @ map (n/% +10)))
+ to (|> r.nat (:: @ map (n/% +10)))
#let [(^open) (&.Eq<List> number.Eq<Nat>)
(^open "&/") &.Functor<List>]]
($_ seq
@@ -208,17 +210,26 @@
(&/map product.left enum-sample))
(= sample
(&/map product.right enum-sample)))))
+
+ (test "Ranges can be constructed forward and backwards."
+ (and (let [(^open "list/") (&.Eq<List> number.Eq<Nat>)]
+ (list/= (&.n/range from to)
+ (&.reverse (&.n/range to from))))
+ (let [(^open "list/") (&.Eq<List> number.Eq<Int>)
+ from (nat-to-int from)
+ to (nat-to-int to)]
+ (list/= (&.i/range from to)
+ (&.reverse (&.i/range to from))))))
))))
## TODO: Add again once new-luxc becomes the standard compiler.
-## (context: "Monad transformer"
-## (let [lift (&.lift io.Monad<IO>)
-## (^open "io/") io.Monad<IO>]
-## (test "Can add list functionality to any monad."
-## (|> (io.run (do (&.ListT io.Monad<IO>)
-## [a (lift (io/wrap 123))
-## b (wrap 456)]
-## (wrap (i/+ a b))))
-## (case> (^ (list 579)) true
-## _ false)))
-## ))
+(context: "Monad transformer"
+ (let [lift (&.lift io.Monad<IO>)
+ (^open "io/") io.Monad<IO>]
+ (test "Can add list functionality to any monad."
+ (|> (io.run (do (&.ListT io.Monad<IO>)
+ [a (lift (io/wrap 123))
+ b (wrap 456)]
+ (wrap (i/+ a b))))
+ (case> (^ (list 579)) true
+ _ false)))))