added buffer argument to OfSeq and OfSeq2

This commit is contained in:
milarin 2024-09-09 10:44:32 +02:00
parent 29e60825bc
commit e7c7fca697

8
of.go
View File

@ -70,8 +70,8 @@ func OfMap[K comparable, V, T any](m map[K]V, unmapper func(K, V) T) <-chan T {
}
// OfSeq returns a channel containing all values provided by the iterator
func OfSeq[T any](seq iter.Seq[T]) <-chan T {
out := make(chan T, 10)
func OfSeq[T any](seq iter.Seq[T], buffer int) <-chan T {
out := make(chan T, buffer)
go func() {
defer close(out)
@ -85,8 +85,8 @@ func OfSeq[T any](seq iter.Seq[T]) <-chan T {
// 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], unmapper func(K, V) T) <-chan T {
out := make(chan T, 10)
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)