3 ms·
Go has a ternary if, but the syntax is weird ;-) n := map[bool]func() int{ false: func() int { return falseExpr }, true: func() in
by junke 10y ago
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/TXIse32WD9 https://play.golang.org/p/TXIse32WD9
Now, let's see how to abstract it with "go generate"...