12345678910111213141516171819202122232425262728293031 | should_nil := yes
int := if should_nil then nil else 123
say "$int (Optional(Int) $(if int then "wasn't" else "was") nil)"
float := if should_nil then nil else 5.5
say "$float (Optional(Num) $(if float then "wasn't" else "was") nil)"
s := if should_nil then nil else "Not nil"
say "$s (Optional(String) $(if s then "wasn't" else "was") nil)"
say(s or "Nah")
fn := if should_nil then nil else (s:String)=> say(s)
maybe_log := fn or (s:String)=> say("...")
maybe_log("Hello")
def maybe_str(s:String,nil_it:Bool):String?
return nil if nil_it
return s
say(maybe_str("hi", no) or "XXX")
foo:= maybe_str("hi", no)
boolnil:= nil:Bool?
boolyes:= yes:Bool?
boolno:= no:Bool?
t := "truthy"
f := "falsey"
say "OptionalBool truthiness: nil=$(if boolnil then t else f) yes=$(if boolyes then t else f) no=$(if boolno then t else f)"
say "OptionalBool equality: nil==nil?$(boolnil==nil) yes==nil?$(boolyes==nil) no==nil?$(boolno==nil)"
say "OptionalBool equality: nil==yes?$(boolnil==yes) yes==yes?$(boolyes==yes) no==yes?$(boolno==yes)"
say "OptionalBool equality: nil==no?$(boolnil==no) yes==no?$(boolyes==no) no==no?$(boolno==no)"
|