<p>When dealing with a single return, it's easy to do: <code>variable += function()</code>, but it doesn't seem possible to do something like <code>var1+=, var2+= = multiReturn()</code> without creating temporary variables and then doing the <code>variable += tempVar</code> on its own line.</p>
<p>Is there a shorter way to do this?</p>
<hr/>**评论:**<br/><br/>rimpy13: <pre><p>Unfortunately, there's not. Is this something that comes up a lot? One of Go's design goals was to keep language size down, and this sometimes comes at the cost of an extra line or two of code, especially in less common scenarios like the one you're describing.</p></pre>code_nomad: <pre><p>Not a lot no, but with how concise go lets you be other places, <code>:=</code> ,<code>defer</code> instead of <code>using()</code>-style blocks, channels instead of mutex nightmare, etc, it feels odd to make throwaway variables.</p></pre>nicerobot: <pre><p>If it was going to be something you needed frequently, one approach I tend to use is simply provide a function that takes the same parameter as the multi-return <a href="https://play.golang.org/p/igDQw-0dmK" rel="nofollow">https://play.golang.org/p/igDQw-0dmK</a></p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
0 回复
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传