Re:Go Chainable: .map().filter().reduce() in Go
by tptacek on Monday March 07, 2022 @01:01AM
(#30584638)
I don't love libraries like this and feel like they work against the idiom in Go; I'm skeptical that things like this will be part of the idiom going forward. But Rust isn't all wine and roses with this stuff either; obviously, it's a much more powerful generics system, but closures are much more annoying to work with than they are in Go, where everything just magically escapes to the heap when you need it to.
Re:Go Chainable: .map().filter().reduce() in Go
by Sytten on Monday March 07, 2022 @01:44AM
(#30584857)
I used to hate the closure from rust but I learned to love it. With golang its a PITA to track down performance issues die to heap escape where it is explicit in rust.
Re:Go Chainable: .map().filter().reduce() in Go
by assbuttbuttass on Monday March 07, 2022 @09:30AM
(#30588211)
Right, go is just not designed for this kind of functional style, and it will always require a lot of boilerplate and fighting the language to try to write code like this.
I predict that production go code will continue to use for loops for this kind of thing, even once generics are widely established.
Re:Go Chainable: .map().filter().reduce() in Go
by saturn_vk on Monday March 07, 2022 @02:09AM
(#30584992)
I agree, the current implementation is really not sufficient, at least for this. I played around with lazy iteration a while back and found the current restrictions would make working with it an annoyance.
I've placed some thoughts in the Readme [1] so I don't forget. Hopefully at least some of the restrictions will be dropped.
Re:Go Chainable: .map().filter().reduce() in Go
by gtramont on Monday March 07, 2022 @12:31AM
(#30584510)
After taking a stab at some more functional approach with generics in Go — https://github.com/gtramontina/go-extlib — I do agree that some of it does feel shoehorned. Although for some other constructs, it feels quite nice. As I mentioned on the readme of the linked repository, this post https://hypirion.com/musings/type-safe-http-servers-in-go-vi... presents pros and cons nicely.
As one who works mostly in Rust and JavaScript and is passingly familiar with Go (I used it for a couple of projects eight and nine years ago), these seem some pretty severe limitations.
Rust’s trait-based iterator system is delightful, so that you can map, filter, reduce, &c. on any iterator, lazily, and even define an extension trait to define your own methods on any iterator, thereafter accessible by just importing that trait.
In the end, I think the current scope of generics and interfaces won’t be enough to produce any feeling other than “shoehorned” for this functional style in Go. It’s just not a style that works well in all types of programming languages.