added OfMap
This commit is contained in:
parent
892814aa5c
commit
944ab39e28
16
of.go
16
of.go
@ -51,3 +51,19 @@ func OfFunc[T any](ctx context.Context, buffer int, f func() T) <-chan T {
|
|||||||
|
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OfMap returns a channel containing the return values of the unmapper function
|
||||||
|
// applied to any key-value pair in m
|
||||||
|
// The order is random
|
||||||
|
func OfMap[K comparable, V, T any](m map[K]V, unmapper func(K, V) T) <-chan T {
|
||||||
|
out := make(chan T, len(m))
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
defer close(out)
|
||||||
|
for k, v := range m {
|
||||||
|
out <- unmapper(k, v)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user