FilterSuccess implemented

This commit is contained in:
milarin 2023-03-25 11:37:08 +01:00
parent 984aae2553
commit b602502992

View File

@ -48,3 +48,12 @@ func (r Result[T]) GetOrDefault(defaultValue T) T {
func (r Result[T]) Get() (T, error) { func (r Result[T]) Get() (T, error) {
return *r.value, r.err return *r.value, r.err
} }
func FilterSuccess[T any](source <-chan Result[T]) <-chan T {
succeeded := Filter(source, func(r Result[T]) bool { return r.Success() })
return MapSuccessive(succeeded, func(r Result[T]) T {
v, _ := r.Get()
return v
})
}