aboutsummaryrefslogtreecommitdiff
path: root/test/optionals.tm
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-09-11 12:29:48 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-09-11 12:29:48 -0400
commit210179ee672a0c3799328a54e886f574b3823e3d (patch)
tree25ddb95503c537c19b9fdb7614df2f16c4012d21 /test/optionals.tm
parentdee3742b48e27ef36637d004163286d3352b0763 (diff)
Optional enums (deprecated custom tag values)
Diffstat (limited to 'test/optionals.tm')
-rw-r--r--test/optionals.tm21
1 files changed, 20 insertions, 1 deletions
diff --git a/test/optionals.tm b/test/optionals.tm
index b80fbab0..a721deaa 100644
--- a/test/optionals.tm
+++ b/test/optionals.tm
@@ -1,11 +1,17 @@
struct Struct(x:Int, y:Text):
- func maybe(should_i:Bool)-> Struct?:
+ func maybe(should_i:Bool)->Struct?:
if should_i:
return Struct(123, "hello")
else:
return !Struct
+enum Enum(X, Y(y:Int)):
+ func maybe(should_i:Bool)->Enum?:
+ if should_i:
+ return Enum.Y(123)
+ else:
+ return !Enum
func maybe_int(should_i:Bool)->Int?:
if should_i:
@@ -143,6 +149,19 @@ func main():
fail("Truthy: $nope")
else: !! Falsey: $nope
+ do:
+ !! ...
+ !! Enums:
+ >> yep := Enum.maybe(yes)
+ = Enum.Y(y=123)?
+ >> nope := Enum.maybe(no)
+ = !Enum
+ >> if yep: >> yep
+ else: fail("Falsey: $yep")
+ >> if nope:
+ fail("Truthy: $nope")
+ else: !! Falsey: $nope
+
if yep := maybe_int(yes):
>> yep
= 123 : Int