fixed OfMap, OfSeq, OfSeq2
This commit is contained in:
parent
d9d7a1586e
commit
29e60825bc
6
of.go
6
of.go
@ -59,7 +59,7 @@ func OfFunc[T any](ctx context.Context, buffer int, f func() T) <-chan T {
|
|||||||
func OfMap[K comparable, V, T any](m map[K]V, unmapper func(K, V) T) <-chan T {
|
func OfMap[K comparable, V, T any](m map[K]V, unmapper func(K, V) T) <-chan T {
|
||||||
out := make(chan T, len(m))
|
out := make(chan T, len(m))
|
||||||
|
|
||||||
defer func() {
|
go func() {
|
||||||
defer close(out)
|
defer close(out)
|
||||||
for k, v := range m {
|
for k, v := range m {
|
||||||
out <- unmapper(k, v)
|
out <- unmapper(k, v)
|
||||||
@ -73,7 +73,7 @@ func OfMap[K comparable, V, T any](m map[K]V, unmapper func(K, V) T) <-chan T {
|
|||||||
func OfSeq[T any](seq iter.Seq[T]) <-chan T {
|
func OfSeq[T any](seq iter.Seq[T]) <-chan T {
|
||||||
out := make(chan T, 10)
|
out := make(chan T, 10)
|
||||||
|
|
||||||
defer func() {
|
go func() {
|
||||||
defer close(out)
|
defer close(out)
|
||||||
for v := range seq {
|
for v := range seq {
|
||||||
out <- v
|
out <- v
|
||||||
@ -88,7 +88,7 @@ func OfSeq[T any](seq iter.Seq[T]) <-chan T {
|
|||||||
func OfSeq2[K comparable, V, T any](seq iter.Seq2[K, V], unmapper func(K, V) T) <-chan T {
|
func OfSeq2[K comparable, V, T any](seq iter.Seq2[K, V], unmapper func(K, V) T) <-chan T {
|
||||||
out := make(chan T, 10)
|
out := make(chan T, 10)
|
||||||
|
|
||||||
defer func() {
|
go func() {
|
||||||
defer close(out)
|
defer close(out)
|
||||||
for key, value := range seq {
|
for key, value := range seq {
|
||||||
out <- unmapper(key, value)
|
out <- unmapper(key, value)
|
||||||
|
Loading…
Reference in New Issue
Block a user