On Wed, Apr 24, 2019 at 8:42 PM David Koblas <da...@koblas.com> wrote:
> IMHO I've wanted a switch expression, rather than a switch statement for a > while. > I've wanted that too, but what we already have really isn't that bad. > value := switch test { > case true => "red" > case false => "blue" > } > > value := "blue" if test { value = "red" } > value := switch item.(type) { > case int => item > case string => strconv.Atoi(item) > case time.Time => { > ... something more involved ... returning an int > } > } > > Note that the above won't work; you must have a default case as well, for almost any switch expression. value := 0 switch v := item.(type) { case int: value = v case string: value = strconv.Atoi(v) case time.Time: ... } > Sure, not as compact as ternary -- but far more powerful and useful. > On 4/24/19 9:40 PM, Michael Jones wrote: > > switch test { > case true: > //..code block for test=true > case false: > //..code block for test=false > } > > On Wed, Apr 24, 2019 at 4:42 PM Dan Kortschak <d...@kortschak.io> wrote: > >> How would you preclude it? >> >> On Wed, 2019-04-24 at 16:28 -0700, lgod...@gmail.com wrote: >> > I am NOT in favor of allowing nested ternary operations >> >> -- >> 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 golang-nuts+unsubscr...@googlegroups.com. >> For more options, visit https://groups.google.com/d/optout. >> > -- > > *Michael T. Jones michael.jo...@gmail.com <michael.jo...@gmail.com>* > -- > 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 golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > > -- > 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 golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- 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 golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.