aboutsummaryrefslogtreecommitdiff
path: root/docs/optionals.md
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-09-11 23:17:03 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-09-11 23:17:03 -0400
commitc034175ae1cbe53bc0e7e1ae71b51c64dcc3402a (patch)
tree8a6b1754c7530399a563d7b80a669d6d08d8af37 /docs/optionals.md
parentcfef667a899339a0fd5b79214d581db6ede10748 (diff)
Add optional:or_else(fallback) and optional:or_fail(message)
Diffstat (limited to 'docs/optionals.md')
-rw-r--r--docs/optionals.md17
1 files changed, 17 insertions, 0 deletions
diff --git a/docs/optionals.md b/docs/optionals.md
index 445a9681..1414ca6a 100644
--- a/docs/optionals.md
+++ b/docs/optionals.md
@@ -28,3 +28,20 @@ func maybe_takes_int(x:Int?):
This establishes a common language for talking about optional values without
having to use a more generalized form of `enum` which may have different naming
conventions and which would generate a lot of unnecessary code.
+
+In addition to using conditionals to check for null values, you can also use
+`:or_else(fallback)` or `:or_fail()`:
+
+```tomo
+maybe_x := 5?
+>> maybe_x:or_else(-1)
+= 5 : Int
+>> maybe_x:or_fail()
+= 5 : Int
+
+maybe_x = !Int
+>> maybe_x:or_else(-1)
+= -1 : Int
+>> maybe_x:or_fail()
+# Failure!
+```