From dee3742b48e27ef36637d004163286d3352b0763 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 11 Sep 2024 12:01:17 -0400 Subject: Optional structs --- test/optionals.tm | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test') 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 -- cgit v1.2.3