Hi community,

The type of yield occurs twice in the function declaration and 
at the return statement.


```


func (s *Set[E]) All() iter.Seq[E] {
    return func(yield func(E) bool) {
        for v := range s.m {
            if !yield(v) {
                return
            }
        }
    }
}


```


How about add yield types like this?
I think it can simplify the code a bit.


```


type Yield[V any] func(V) bool
type Yield2[K, V any] func(K, V) bool


func sliceDemo[K int, V any](s []V) func(Yield2[K, V]) {
        return func(yield Yield2[K, V]) {
                for i, v := range s {
                        if !yield(K(i), v) {
                                break
                        }
                }
        }
}


func mapDemo[K comparable, V any](s map[K]V) func(Yield2[K, V]) {
        return func(yield Yield2[K, V]) {
                for i, v := range s {
                        if !yield(i, v) {
                                break
                        }
                }
        }
}


```

-- 
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 on the web visit 
https://groups.google.com/d/msgid/golang-nuts/tencent_7983E02A0C5363ABC9B43CD458E0A1B7FC07%40qq.com.

Reply via email to