Hello, I would like to first thank those in the know here are so helpful!
I’m pretty surprised this code works. It take a generated stream and returns the proper values of the bool “if prime”. I would prefer to only print out “prime:X”. For this I have notSmartPrime1, but I have to print “Prime:0” when it isn’t prime. I would rather not print anything at all. Any ideas?
notSmartPrime := func(
done <-chan interface{},
primeStream <-chan int,
) <-chan bool {
localStream := make(chan bool)
go func() {
defer close(localStream)
for v := range primeStream {
select {
case <-done:
return
case localStream <- isPrime(uint64(v)):
}
}
}()
return localStream
}
notSmartPrime1 := func(
done <-chan interface{},
primeStream <-chan int,
) <-chan int {
localStream := make(chan int)
go func() {
defer close(localStream)
localPrime := 0
for v := range primeStream {
if isPrime(uint64(v)) {
localPrime = v
} else {
localPrime = 0
}
select {
case <-done:
return
case localStream <- localPrime:
}
}
}()
return localStream
}