aboutsummaryrefslogtreecommitdiff
path: root/test/reductions.tm
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-11-02 20:22:19 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-11-02 20:22:19 -0400
commit0b7a0dd043a4c7ccfc924d618508d1edc0115e2f (patch)
tree6e1942840ab7e1e10bed111d8d5a012eacdf8b9b /test/reductions.tm
parent985011aed89706e9a4b06e6c6f3239d53ac8e6e8 (diff)
Change reducers to use (OP: ...) syntax and return an optional value
Diffstat (limited to 'test/reductions.tm')
-rw-r--r--test/reductions.tm29
1 files changed, 19 insertions, 10 deletions
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