<p>Anyone recommend something like underscore or lodash for Go?</p>
<hr/>**评论:**<br/><br/>garfj: <pre><p>Take a look at <a href="https://github.com/go-goast/goast">goast</a> in conjunction with the <a href="https://github.com/go-goast/iter">iter</a> package. </p></pre>davecheney: <pre><p><a href="http://tobyhede.github.io/underscore.go/">underscore.go</a></p></pre>tarrsalah: <pre><p>A quote from <a href="https://github.com/robpike/filter">https://github.com/robpike/filter</a> Rob Pike</p>
<blockquote>
<p>Having written it a couple of years ago, I haven't had occasion to
use it once. Instead, I just use "for" loops.</p>
<p>You shouldn't use it either.</p>
</blockquote></pre>YEPHENAS: <pre><p>Don't do that. It's not idiomatic.</p></pre>SingularityNow: <pre><p>What exactly isn't idiomatic? Having a collection of common slice operations? </p></pre>icholy: <pre><p>When that involves unsafe code that relies on reflection ... yes.</p></pre>SingularityNow: <pre><p>Who was talking about unsafe or code or reflection?</p></pre>icholy: <pre><p>True, i was referring to implementations like underscore.go </p></pre>SingularityNow: <pre><p>Right, I figured. No worries.</p>
<p>Given the recent push of <code>go generate</code> I'm just starting to think code generation idea's should gain some traction. Seems like there's probably a way to do all that and keep type safety and skip reflection altogether.</p>
<ul>
<li><a href="http://clipperhouse.github.io/gen/" rel="nofollow">http://clipperhouse.github.io/gen/</a></li>
<li><a href="https://github.com/go-goast/goast" rel="nofollow">https://github.com/go-goast/goast</a></li>
<li><a href="https://github.com/droundy/gotgo" rel="nofollow">https://github.com/droundy/gotgo</a></li>
</ul></pre>klaaax: <pre><p>I'd argue it doesn't matter if it compiles and runs.</p>
<p>I've seen a lot of so called "non idiomatic Go" inside the go core library itself, to dodge Go language limitations,interface{} everywhere , heavy reflection,... if the Go team itself does it then it's idiomatic.</p></pre>xsolarwindx: <pre><p>There's a difference between idiomatic and reflection. This library is not idiomatic. There's a clearly defined idiomatic way to do what this library is doing, and that's by using loops. </p></pre>klaaax: <pre><p>I don't see what the problem is, somewhere in the code a for loop is used to iterate over an array. Are you saying it isn't idiomatic to wrap for loops into functions in go in order to write clean code without unnecessary noise?</p></pre>YEPHENAS: <pre><blockquote>
<p>isn't idiomatic to wrap for loops into functions in go in order to write clean code without unnecessary noise?</p>
</blockquote>
<p>It's definitely not idiomatic Go to perform micro-DRY on control structures.</p></pre>SingularityNow: <pre><p>The 'zip' pattern is a control structure now? </p></pre>ijustwantaredditacct: <pre><p><a href="http://golang.org/pkg/container/ring/#Ring.Do" rel="nofollow">abstracting</a>
<a href="http://golang.org/src/go/ast/walk.go?s=6267:6309#L374" rel="nofollow">traversal</a> is totally non idiomatic.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传