Assuming I'm not wrong, this is my updated proposal:

package iter

// Push takes a consumer function, and returns a yield and a stop function.
// It arranges for the consumer to be called with a Seq iterator.
// The iterator will return all the values passed to the yield function.
// The iterator will stop when the stop function is called.
func Push[V any](consumer func(seq iter.Seq[V])) (yield func(V) bool, stop 
func())

This is the implementation:
https://github.com/ncruces/go-sqlite3/blob/8adb838/ext/seq/push.go

Regards,
Nuno

On Wednesday 26 February 2025 at 10:18:15 UTC Nuno Cruces wrote:

> Hi Ian,
>
> On Tuesday 25 February 2025 at 18:15:40 UTC Ian Lance Taylor wrote:
>
> 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())
>
>
> I haven't been able to make this interface work to hide the goroutine 
> logic from the caller (which IMO is most of the point).
>
> I may be missing something but ISTM that for this to work (and when 
> implemented with channels) the *caller* of seq(yield) needs to run in its 
> own goroutine.
> So, if we return seq(yield), we force the caller of Push to then spin a 
> goroutine to call seq (and it becomes harder to enforce no parallelism).
>
> Am I wrong?
>
> Thanks again!
> Nuno Cruces
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/golang-nuts/92e09456-8d52-4914-94d8-7042a6d05550n%40googlegroups.com.

Reply via email to