News for hackers. Stuff that matters.
Re:Functional Programming in Go with Generics by duped on Thursday May 27, 2021 @03:02PM (#27306789)
This isn't "lots of science" it's rudimentary software engineering...

Sending data through channels just to implement an iterator seems insane. It's not strictly lazy either...

Why do go developers reject simple patterns that make faster code?

Re:Functional Programming in Go with Generics by rad_gruchalski on Thursday May 27, 2021 @03:54PM (#27307431)
How are those magical lazy operations implemented in other languages? Someone had to take that insane step. It’s just not by default in go.

Look, I’ve written lots of scala and erlang so I get your argument. It just does not exist in go. And that’s okay.

Never got caught thinking “gee, need a lazy collection”. Maybe a stream when reading stuff from the ether. In go, channel was enough. 5 minute job. Nothing insane.

Re:Functional Programming in Go with Generics by duped on Thursday May 27, 2021 @05:18PM (#27308683)
They're implemented with closures, not passing things through FIFOs. It's not magic. You barely need a compiler pass to implement the sugar for `for` loops: it's a trivial transformation to a `while`.
Re:Functional Programming in Go with Generics by rad_gruchalski on Thursday May 27, 2021 @06:10PM (#27309206)
Okay, but what’s the benefit for go. I can iterate over slices, maps and channels (for ... range). Slices must have a capacity defined. What’s the benefit of lazy iterator?

for over a channel is in essence lazy. Channel stores the data as a linked list. So what’s the benefit.

Re:Functional Programming in Go with Generics by duped on Thursday May 27, 2021 @07:36PM (#27309957)
The benefit of generic iterators or implementing iterators lazily? The benefit of generic iterators is that they make SOLID programs easy to write, especially when converting data. It makes any kind of data ingest or hand rolled parsing/semantic analysis easy to write, read, and hard to screw up - which is 90% of business logic.

Lazy evaluation is the only reasonable way to implement iterators so you don't have to pay the costs of intermediate data structures or sending data over channels. Insertion into a data structure isn't free. Function composition is.