On Fri, 2016-08-05 at 08:57 -0700, dc0d wrote:
> In Go we can write:
>
> if _, ok := input.(*data); ok {
> //...
> }
>
> Why is it we can't do that in the case clause of a switch statement:
>
> switch {
> case x1,ok:=input.(*data1); ok && otherCond1:
> case x2,ok:=input.(*data2); ok && otherCond2:
> }
>
> (I've read the language specification - which BTW speaks about the "case
> expressions" - I'm just curious about the reason)
In the more general case there are times that this might be nice, but
isn't the above more clearly expressible as
switch x := input.(type) {
case *data1:
if !otherCond1 {
break
}
// stuff
case *data2:
if !otherCond2 {
break
}
// stuff
}
since it's really a type switch.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.