diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-16 16:06:19 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-16 16:06:19 -0400 |
| commit | de49bc5bb3198f450cb367085f9def0d89782258 (patch) | |
| tree | a81354271bd3de567a7656807416cd5c69e4b08b /docs/optionals.md | |
| parent | 821bde156c222c7384c67517d773dc14a03342e7 (diff) | |
Deprecate :or_else()/:or_fail()/:or_exit() in favor of the `or` operator
Diffstat (limited to 'docs/optionals.md')
| -rw-r--r-- | docs/optionals.md | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/docs/optionals.md b/docs/optionals.md index 54fe5f5c..2bc747f9 100644 --- a/docs/optionals.md +++ b/docs/optionals.md @@ -30,25 +30,28 @@ 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()` or `:or_exit()`: +`or` to get a non-null value by either providing an alternative non-null value +or by providing an early out statement like `return`/`skip`/`stop` or a function +with an `Abort` type like `fail()` or `exit()`: ```tomo maybe_x := 5? ->> maybe_x:or_else(-1) +>> maybe_x or -1 = 5 : Int ->> maybe_x:or_fail() +>> maybe_x or fail("No value!") = 5 : Int maybe_x = !Int ->> maybe_x:or_else(-1) +>> maybe_x or -1 = -1 : Int ->> maybe_x:or_fail("No value!") +>> maybe_x or fail("No value!") # Failure! +func do_stuff(matches:[Text]): + pass -maybe_x = !Int ->> maybe_x:or_exit() -= -1 : Int ->> maybe_x:or_exit("No value!") -# Exit! +for line in lines: + matches := line:matches($/{..},{..}/) or skip + # The `or skip` above means that if we're here, `matches` is non-null: + do_stuff(matches) ``` |
