diff --git a/result.go b/result.go index cfd7b7e..b25f5c1 100644 --- a/result.go +++ b/result.go @@ -49,6 +49,17 @@ func (r Result[T]) Get() (T, error) { return *r.value, r.err } +func (r Result[T]) GetSafe() T { + if r.err != nil { + panic(r.err) + } + return *r.value +} + +func (r Result[T]) Err() error { + return r.err +} + func FilterSuccess[T any](source <-chan Result[T]) <-chan T { succeeded := Filter(source, func(r Result[T]) bool { return r.Success() }) @@ -76,13 +87,11 @@ func FilterResults[T any](source <-chan Result[T]) (succeeded <-chan T, failed < defer close(fail) for r := range source { - v, err := r.Get() - - if err == nil { - succ <- v - } else { - fail <- err + if r.Fail() { + fail <- r.Err() + continue } + succ <- r.GetSafe() } }()