diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-11 12:01:17 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-11 12:01:17 -0400 |
| commit | dee3742b48e27ef36637d004163286d3352b0763 (patch) | |
| tree | 881a9a25b4cfeb6ff632a3fa48ccd3abd7f642ae /test/optionals.tm | |
| parent | bba9f1b141fba5ffc366ef9377fb3089c0c5a1a3 (diff) | |
Optional structs
Diffstat (limited to 'test/optionals.tm')
| -rw-r--r-- | test/optionals.tm | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/optionals.tm b/test/optionals.tm index 8e24f66d..b80fbab0 100644 --- a/test/optionals.tm +++ b/test/optionals.tm @@ -1,3 +1,12 @@ + +struct Struct(x:Int, y:Text): + func maybe(should_i:Bool)-> Struct?: + if should_i: + return Struct(123, "hello") + else: + return !Struct + + func maybe_int(should_i:Bool)->Int?: if should_i: return 123 @@ -121,6 +130,18 @@ func main(): fail("Truthy: $nope") else: !! Falsey: $nope + do: + !! ... + !! Structs: + >> yep := Struct.maybe(yes) + = Struct(x=123, y="hello")? + >> nope := Struct.maybe(no) + = !Struct + >> if yep: >> yep + else: fail("Falsey: $yep") + >> if nope: + fail("Truthy: $nope") + else: !! Falsey: $nope if yep := maybe_int(yes): >> yep |
