Find operations added
This commit is contained in:
parent
19959a6c01
commit
a85ba0011d
32
find.go
Normal file
32
find.go
Normal file
@ -0,0 +1,32 @@
|
||||
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 {
|
||||
Flush(source)
|
||||
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
|
||||
}
|
Loading…
Reference in New Issue
Block a user