From b602502992ae7ba1bb8c2ce769008a447eb4b76c Mon Sep 17 00:00:00 2001 From: milarin Date: Sat, 25 Mar 2023 11:37:08 +0100 Subject: [PATCH] FilterSuccess implemented --- result.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/result.go b/result.go index 87d4feb..5fc9054 100644 --- a/result.go +++ b/result.go @@ -48,3 +48,12 @@ func (r Result[T]) GetOrDefault(defaultValue T) T { func (r Result[T]) Get() (T, error) { 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 + }) +}