Compare commits

..

No commits in common. "main" and "v0.1.7" have entirely different histories.
main ... v0.1.7

2 changed files with 2 additions and 32 deletions

2
go.mod
View File

@ -1,3 +1,3 @@
module git.milar.in/milarin/channel
go 1.23
go 1.18

32
of.go
View File

@ -2,7 +2,6 @@ package channel
import (
"context"
"iter"
"time"
)
@ -59,7 +58,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 {
out := make(chan T, len(m))
go func() {
defer func() {
defer close(out)
for k, v := range m {
out <- unmapper(k, v)
@ -68,32 +67,3 @@ func OfMap[K comparable, V, T any](m map[K]V, unmapper func(K, V) T) <-chan T {
return out
}
// OfSeq returns a channel containing all values provided by the iterator
func OfSeq[T any](seq iter.Seq[T], buffer int) <-chan T {
out := make(chan T, buffer)
go func() {
defer close(out)
for v := range seq {
out <- v
}
}()
return out
}
// OfSeq2 returns a channel containing the return values of the unmapper function
// when provided with the values of the iterator
func OfSeq2[K comparable, V, T any](seq iter.Seq2[K, V], buffer int, unmapper func(K, V) T) <-chan T {
out := make(chan T, buffer)
go func() {
defer close(out)
for key, value := range seq {
out <- unmapper(key, value)
}
}()
return out
}