Last active
March 11, 2025 13:03
-
-
Save earthboundkid/82bc25076a8aa8a162dc4a669b161d8c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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