-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
guard
-else
#1215
Comments
Supersedes #756 I suppose |
A couple thoughts: I'm reluctant to add any more reserved words like Maybe upgrading pipes to better handle piping to
Possible conditional pipe options: |
unless-else reads like a double-negative, but otherwise I'd be fine with it. |
Pipe conditions do seem like a reasonable possible approach. We might need one for truthy and one for nonnull. We've talked about Given how much unless x? := getX()
throw new Error "Missing x coordinate"
unless y? := getY() then return
unless z? := getZ() then return
setPoint x, y, z #756 points out that our current meaning of Alternatively, we could pull the declaration outside: x := getX() ?? throw new Error "Missing x coordinate"
y := getY() ?? return
z := getZ() ?? return
setPoint x, y, z This works for |
Now that we have
isExit
for other reasons, Swift-styleguard
seems implementable. At first glance, it seems identical tounless
:However, there are two key differences:
guard x? := getX() else { ... }
), the bindings are only available outside theelse
block.STATEMENTS
must be an "exit" of some sort, in order for1
to be possible.The primary use case is to prevent "pyramids of doom" when there are many bindings to be done:
The text was updated successfully, but these errors were encountered: