2022-12-19 18:01:38 +01:00
|
|
|
package channel
|
|
|
|
|
|
|
|
func FindFirst[T any](source <-chan T) *T {
|
|
|
|
for v := range source {
|
|
|
|
return &v
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func FindFirstAndFlush[T any](source <-chan T) *T {
|
|
|
|
for v := range source {
|
2022-12-19 18:03:43 +01:00
|
|
|
go Flush(source)
|
2022-12-19 18:01:38 +01:00
|
|
|
return &v
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func FindLast[T any](source <-chan T) *T {
|
|
|
|
var last *T = new(T)
|
|
|
|
found := false
|
|
|
|
|
|
|
|
for v := range source {
|
|
|
|
*last = v
|
|
|
|
found = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if !found {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return last
|
|
|
|
}
|