Skip to content

Instantly share code, notes, and snippets.

@earthboundkid
Last active March 11, 2025 13:03
Show Gist options
  • Save earthboundkid/82bc25076a8aa8a162dc4a669b161d8c to your computer and use it in GitHub Desktop.
Save earthboundkid/82bc25076a8aa8a162dc4a669b161d8c to your computer and use it in GitHub Desktop.
func Push[V any](consumer func(seq iter.Seq[V])) (yield func(V) bool, stop func()) {
var in V
coro := func(coroYield func(struct{}) bool) {
seq := func(seqYield func(V) bool) {
for seqYield(in) {
if !coroYield(struct{}{}) {
break
}
}
}
consumer(seq)
}
next, stop := iter.Pull(coro)
yield = func(v V) bool {
in = v
_, more := next()
if !more {
stop()
}
return more
}
return yield, stop
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment