3 ms·
I like to do it this way x := func() Type { if val { return foo() } return bar() }()
by thegeekpirate 5y ago
I like to do it this way
x := func() Type {
if val {
return foo()
}
return bar()
}()
- maccard 5y agoI've used that one in C++ quite a lot for const initializing variables that have awkward initialization steps, and it's probably my favourite of the options, but it's still nasty; having to declare the return type of the function removes one of my favourite things about golang!
- boring_twenties 5y agoThis is supposed to be ... easier to read than `x := val ? foo() : bar()`? Really?
- deleted 5y ago[deleted]