Re:My Go Resolutions for 2017
by koblas on Thursday January 19, 2017 @08:44AM
(#13435670)
It's worse that that, since you need to declare the variable as well. It's the "var n int" piece that bugs me, since sometimes you're moving code around and have a n := trueVal hidden in there.
[ Parent
| on HN ]
Go has a ternary if, but the syntax is weird ;-)
n := map[bool]func() int{
false: func() int { return falseExpr },
true: func() int { return trueExpr },
}[expr]()
https://play.golang.org/p/TXIse32WD9Now, let's see how to abstract it with "go generate"...