diff --git a/of.go b/of.go index d14e687..af33cd1 100644 --- a/of.go +++ b/of.go @@ -51,3 +51,19 @@ func OfFunc[T any](ctx context.Context, buffer int, f func() T) <-chan T { 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 +}