Is this so bad? func ternary(cond bool, pos, neg interface{}) interface{} { if cond { return pos } else { return neg } }
color := ternary( temp < 80, "blue", "red") On Wed, Apr 24, 2019 at 4:14 PM Chris Broadfoot <ch...@chrisbroadfoot.id.au> wrote: > > > On Wed, Apr 24, 2019 at 4:22 AM Robert Engels <reng...@ix.netcom.com> > wrote: > >> Though to the ops point, not sure why Go doesn’t have the ternary >> operator - which is pretty ubiquitous. >> > > https://golang.org/doc/faq#Does_Go_have_a_ternary_form > > >> >> On Apr 23, 2019, at 9:56 PM, Robert Engels <reng...@ix.netcom.com> wrote: >> >> Why? You have saved 5 characters for no practical gain. I think you would >> enjoy Ada. >> >> On Apr 23, 2019, at 8:05 PM, lgod...@gmail.com wrote: >> >> It sure would be nice if Go syntax allowed programmers to replace >> >> if ( test) { >> ...do sonething >> } else { >> ..do something else >> } >> >> with >> >> ? (test) { >> //...do something >> } >> { >> //..do something else >> } >> >> The ? operator can be anything the Go language team considers appropriate >> >> -- >> 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. > -- 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.