I wanted to implement this "push like" interface with a "processor" function that accepts an iter.Seq and returns a result:func processor(seq iter.Seq[value]) result { ... }
/* output:
consumer sees 0
consumer sees 1
producer exits.
consumer sees 2
consumer done.
all done. sum = 3
*/
Second using iter.Seq:
package main
import "iter"
func consumeAndSum(it iter.Seq[int]) (sum int) {On Feb 24, 2025, at 8:53 PM, Jason E. Aten <j.e....@gmail.com> wrote:
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/6f090b16-ac52-4ea0-b5ea-1f7b3b7e6e7cn%40googlegroups.com.
I don't think we are likely to simply export newcoro and coroswitch,
as they don't provide any functionality that we can't already get from
goroutines, but are harder to use correctly. If someone can define a
clean API that uses them based on channels, we could consider a
proposal for that.
Ian
You don’t need co routines if you have real concurrency. The generator use case is simply an optimization that wouldn’t be necessary if the concurrency model was more efficient - and there was a more expressive way to use it.
I think the Java loom project has proved that the Go concurrency model is ideal. Reading up on “structured concurrency” is a great exercise.
I'm… sorry. I don't understand the purpose of this code listing.In my original post I gave a solution to my own problem implemented in two ways: with goroutines and channels, and with newcoro and coroswitch. If you're trying to show me that I don't need either of those, that iter.Seq is enough, I would kindly ask that you reconsider, and try to implement my interface that way. I don't think it's possible, but I'll be really happy if you can prove me wrong.
On Feb 25, 2025, at 5:57 AM, Jason E. Aten <j.e....@gmail.com> wrote:
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/8f12ea21-0d26-4864-8a08-a6c558a10ed7n%40googlegroups.com.
On Feb 25, 2025, at 7:17 AM, Robert Engels <ren...@ix.netcom.com> wrote:
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/F90571DB-277A-443A-BDE4-0D7A614CF2F1%40ix.netcom.com.
On Feb 25, 2025, at 8:02 AM, Robert Engels <ren...@ix.netcom.com> wrote:
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/E7368238-3921-4DB7-90C6-085B6E91A67E%40ix.netcom.com.
The problem specification you originally gave was this:> "to implement... a "processor" function that accepts an iter.Seq and returns a result:> func processor(seq iter.Seq[value]) result { ... }"
type AggregateFunction interface {// Step is invoked to add a row to the current window.// The function arguments, if any, corresponding to the row being added, are passed to Step.// Implementations must not retain arg.Step(ctx Context, arg ...Value)
// Value is invoked to return the current (or final) value of the aggregate.Value(ctx Context)}
func sum(seq iter.Seq[float64]) float64 {count := 0total := 0.0for arg := range seq {total += argcount++}return total / float64(count)}
Moreover, you originally said,"I've been cracking my head, and I'm convinced I can't with just iter.Seq/iter.Pull"
Which says, in contradiction to your later comment/claim, that you did not have a solutionwhen you asked for one.
The code I provided demonstrates that a solution to the stated problem is indeed possiblewith iter.Seq.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/CAM0U__8k6%2BEiKZO%3DUuxXkVjVh8w6y%2BG9Zc0j2eH3GU02XiJ_iQ%40mail.gmail.com.
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/-Kmtx-sr3G8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcWmTubCfieowziq9BgyqiJddp6sv2g%3Dm4v44FF5P-5aHg%40mail.gmail.com.
I think what you're presenting is an argument for
package iter
// Push returns an iterator, a yield function, and a stop function.
// The iterator will return all the values passed to the yield function.
// The iterator will stop when the stop function is called.
// This provides a way to flexibly convert a sequence of values into a Seq.
func Push[E any]() (seq iter.Seq[E], yield func(E), stop func())