Compare commits

...

2 Commits

Author SHA1 Message Date
169f978e14 fixed argument order 2023-01-16 15:15:21 +01:00
3a80460c18 more FindFirst variants 2023-01-16 15:13:07 +01:00

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](source <-chan T, cancel context.CancelFunc) *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](source <-chan T, cancel context.CancelFunc) *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