diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-11 12:29:48 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-11 12:29:48 -0400 |
| commit | 210179ee672a0c3799328a54e886f574b3823e3d (patch) | |
| tree | 25ddb95503c537c19b9fdb7614df2f16c4012d21 /test/optionals.tm | |
| parent | dee3742b48e27ef36637d004163286d3352b0763 (diff) | |
Optional enums (deprecated custom tag values)
Diffstat (limited to 'test/optionals.tm')
| -rw-r--r-- | test/optionals.tm | 21 |
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 |
