aboutsummaryrefslogtreecommitdiff
path: root/docs/operators.md
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 /docs/operators.md
parent985011aed89706e9a4b06e6c6f3239d53ac8e6e8 (diff)
Change reducers to use (OP: ...) syntax and return an optional value
Diffstat (limited to 'docs/operators.md')
-rw-r--r--docs/operators.md16
1 files changed, 8 insertions, 8 deletions
diff --git a/docs/operators.md b/docs/operators.md
index 85e53242..4afa3ad3 100644
--- a/docs/operators.md
+++ b/docs/operators.md
@@ -50,13 +50,13 @@ reducers in action:
```tomo
>> nums := [10, 20, 30]
->> (+) nums
+>> (+: nums)!
= 60
->> (or) n > 15 for n in nums
+>> (or: n > 15 for n in nums)!
= yes
>> texts := ["one", "two", "three"]
->> (++) texts
+>> (++: texts)!
= "onetwothree"
```
@@ -75,7 +75,7 @@ if you use a reducer on something that has no values:
```tomo
>> nums := [:Int]
->> (+) nums
+>> (+: nums)!
Error: this collection was empty!
```
@@ -84,7 +84,7 @@ If you want to handle this case, you can either wrap it in a conditional
statement or you can provide a fallback option with `else` like this:
```tomo
->> (+) nums else: 0
+>> (+: nums) or 0
= 0
```
@@ -103,10 +103,10 @@ struct Foo(x,y:Int):
>> foos := [Foo(1, 2), Foo(-10, 20)]
->> (+).x foos
+>> (+.x: foos)
= -9
// Shorthand for:
->> (+) f.x for f in foos
+>> (+: f.x for f in foos)
= -9
>> (or):is_even() foos
@@ -114,7 +114,7 @@ struct Foo(x,y:Int):
// Shorthand for:
>> (or) f:is_even() for f in foos
->> (+).x:abs() foos
+>> (+.x:abs(): foos)
= 11
```