more FindFirst variants

This commit is contained in:
milarin 2023-01-16 15:13:07 +01:00
parent ba2efffd8e
commit 3a80460c18

19
find.go
View File

@ -1,5 +1,7 @@
package channel
import "context"
func FindFirst[T any](source <-chan T) *T {
for v := range source {
return &v
@ -7,6 +9,14 @@ func FindFirst[T any](source <-chan T) *T {
return nil
}
func FindFirstAndCancel[T any](cancel context.CancelFunc, source <-chan T) *T {
for v := range source {
cancel()
return &v
}
return nil
}
func FindFirstAndFlush[T any](source <-chan T) *T {
for v := range source {
go Flush(source)
@ -15,6 +25,15 @@ func FindFirstAndFlush[T any](source <-chan T) *T {
return nil
}
func FindFirstAndCancelFlush[T any](cancel context.CancelFunc, source <-chan T) *T {
for v := range source {
cancel()
go Flush(source)
return &v
}
return nil
}
func FindLast[T any](source <-chan T) *T {
var last *T = new(T)
found := false