diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-11-02 20:22:19 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-11-02 20:22:19 -0400 |
| commit | 0b7a0dd043a4c7ccfc924d618508d1edc0115e2f (patch) | |
| tree | 6e1942840ab7e1e10bed111d8d5a012eacdf8b9b /test | |
| parent | 985011aed89706e9a4b06e6c6f3239d53ac8e6e8 (diff) | |
Change reducers to use (OP: ...) syntax and return an optional value
Diffstat (limited to 'test')
| -rw-r--r-- | test/integers.tm | 8 | ||||
| -rw-r--r-- | test/iterators.tm | 4 | ||||
| -rw-r--r-- | test/minmax.tm | 2 | ||||
| -rw-r--r-- | test/reductions.tm | 29 |
4 files changed, 26 insertions, 17 deletions
diff --git a/test/integers.tm b/test/integers.tm index eb0c3fed..8d34dfc0 100644 --- a/test/integers.tm +++ b/test/integers.tm @@ -89,7 +89,7 @@ func main(): = 11 >> 11:prev_prime() = 7 - >> (and) p:is_prime() for p in [ + >> (and: p:is_prime() for p in [ 2, 3, 5, 7, 137372146048179869781170214707, 811418847921670560768224995279, @@ -101,15 +101,15 @@ func main(): 548605069630614185274710840981, 121475876690852432982324195553, 771958616175795150904761471637, - ] + ])! = yes - >> (or) p:is_prime() for p in [ + >> (or: p:is_prime() for p in [ -1, 0, 1, 4, 6, 137372146048179869781170214707*2, 811418847921670560768224995279*3, 292590241572454328697048860273*754893741683930091960170890717, - ] + ])! = no >> Int(yes) diff --git a/test/iterators.tm b/test/iterators.tm index fca91b2d..d6bcfa13 100644 --- a/test/iterators.tm +++ b/test/iterators.tm @@ -19,7 +19,7 @@ func range(first:Int, last:Int -> func(->Int?)): func main(): values := ["A", "B", "C", "D"] - >> ((++) "($(foo.x)$(foo.y))" for foo in pairwise(values)) + >> (++: "($(foo.x)$(foo.y))" for foo in pairwise(values))! = "(AB)(BC)(CD)" >> ["$(foo.x)$(foo.y)" for foo in pairwise(values)] = ["AB", "BC", "CD"] @@ -34,5 +34,5 @@ func main(): >> [i for i in range(5, 10)] = [5, 6, 7, 8, 9, 10] - >> (+) range(5, 10) + >> (+: range(5, 10))! = 45 diff --git a/test/minmax.tm b/test/minmax.tm index fa0e8bd8..a5dd984e 100644 --- a/test/minmax.tm +++ b/test/minmax.tm @@ -23,5 +23,5 @@ func main(): >> foos := [Foo(5, 1), Foo(5, 99), Foo(-999, -999)] - >> (_max_) foos + >> (_max_: foos)! = Foo(x=5, y=99) diff --git a/test/reductions.tm b/test/reductions.tm index 47f1612a..7bfe212a 100644 --- a/test/reductions.tm +++ b/test/reductions.tm @@ -1,25 +1,34 @@ struct Foo(x,y:Int) func main(): - >> (+) [10, 20, 30] + >> (+: [10, 20, 30]) + = 60? + + >> (+: [:Int]) + = !Int + + >> (+: [10, 20, 30]) or 0 = 60 - >> (_max_) [3, 5, 2, 1, 4] - = 5 + >> (+: [:Int]) or 0 + = 0 + + >> (_max_: [3, 5, 2, 1, 4]) + = 5? - >> (_max_:abs()) [1, -10, 5] - = -10 + >> (_max_:abs(): [1, -10, 5]) + = -10? - >> (_max_) [Foo(0, 0), Foo(1, 0), Foo(0, 10)] + >> (_max_: [Foo(0, 0), Foo(1, 0), Foo(0, 10)])! = Foo(x=1, y=0) - >> (_max_.y) [Foo(0, 0), Foo(1, 0), Foo(0, 10)] + >> (_max_.y: [Foo(0, 0), Foo(1, 0), Foo(0, 10)])! = Foo(x=0, y=10) - >> (_max_.y:abs()) [Foo(0, 0), Foo(1, 0), Foo(0, 10), Foo(0, -999)] + >> (_max_.y:abs(): [Foo(0, 0), Foo(1, 0), Foo(0, 10), Foo(0, -999)])! = Foo(x=0, y=-999) !! (or) and (and) have early out behavior: - >> (or) i == 3 for i in 9999999999999999999999999999 + >> (or: i == 3 for i in 9999999999999999999999999999)! = yes - >> (and) i < 10 for i in 9999999999999999999999999999 + >> (and: i < 10 for i in 9999999999999999999999999999)! = no |
