You actually can do simple let-bindings in if-let and guard-let via the `case
let` syntax:
guard case let r = returnsResult(), case let .Succeed(m) = r else { ... }
Although the problem with this is `r` still isn't visible inside of the else
block, because it's part of the guard statement and
> Am 28.12.2015 um 02:31 schrieb Kevin Ballard via swift-evolution
> :
>
> You actually can do simple let-bindings in if-let and guard-let via the `case
> let` syntax:
>
> guard case let r = returnsResult(), case let .Succeed(m) = r else { ... }
>
> Although the
Wait, no, there's a problem with that. You can't use `r` in the guard scope
because `returnsResult()` might not have succeeded.
Félix
> Le 24 déc. 2015 à 09:37:36, Félix Cloutier via swift-evolution
> a écrit :
>
> I like that it's consistent with the if syntax
I feel exactly like Brent.
Félix
> Le 23 déc. 2015 à 04:15:24, Brent Royal-Gordon via swift-evolution
> a écrit :
>
>> guard case let .Succeed(m) = returnsResult() else {
>>return it
>> }
>> // Can safely use m, otherwise Result is passed back the call
In fact, I feel the same way too. I have definite views about indefinite
pronouns. When I am teaching, I studiously avoid “it”, “this”, and “that”: at
any given instant half the students have wandering minds, and if they miss the
referent, they get lost. My old HyperTalk habits must be
Yes, which would revert to Brent’s suggestion. But you have generalized it in a
very compatible way.
As I read somewhere, improving programming languages comes from removing
limitations rather than adding features. I intend for this Pitch to be the
former, although it does kind of look like
More progress! This sounds good, but it looks like what you intend is for r to
be the error message in the Result enum type.
enum Result {
case .Fail(String)// Error message
case .Succeed(MyType) // Something to work with
}
guard case let .Succeed(m) = returnsResult() else case let
> On Dec 23, 2015, at 3:56 PM, Andrew Duncan wrote:
>
> More progress! This sounds good, but it looks like what you intend is for r
> to be the error message in the Result enum type.
>
> enum Result {
> case .Fail(String)// Error message
> case .Succeed(MyType) //
> What about an enumeration with three cases?
>
> For example:
>
> enum Result {
> case Success
> case Failure
> case Cancelled
> }
What about it? The case permitted by the `guard` continues through the
surrounding scope; the other cases are handled by the `else` block.
--
Brent
> On Dec 22, 2015, at 11:58 PM, Andrew Duncan via swift-evolution
> wrote:
>
> Motivation
>
> The guard statement rescues us from the pyramid of doom, and lets our code
> hug the left margin more... if the failure case is false or nil. I'd like to
> guard against
>guard case let .Succeed(m) = returnsResult() else {
> return it
>}
>// Can safely use m, otherwise Result is passed back the call stack.
I didn't understand what you wanted to begin with, so to summarize: you want to
be able to bind the return value of `returnsResult()` to a
11 matches
Mail list logo