From 3dfcee4ee4971e0828a5220812bd6282e39f179e Mon Sep 17 00:00:00 2001 From: milarin Date: Thu, 4 Apr 2024 19:07:52 +0200 Subject: [PATCH] fixed Get and GetUnsafe methods for Result struct --- result.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/result.go b/result.go index b25f5c1..cb1fa71 100644 --- a/result.go +++ b/result.go @@ -17,7 +17,7 @@ func WrapMapFunc[I, O any](f func(I) (O, error)) func(I) Result[O] { return func(i I) Result[O] { return ResultOf(f(i)) } } -func WrapMapResultFunc[I, O any](f func(I) (O, error)) func(Result[I]) Result[O] { +func ResultFunc[I, O any](f func(I) (O, error)) func(Result[I]) Result[O] { resFunc := WrapMapFunc(f) nilValue := *new(O) return func(r Result[I]) Result[O] { @@ -46,10 +46,13 @@ func (r Result[T]) GetOrDefault(defaultValue T) T { } func (r Result[T]) Get() (T, error) { + if r.err != nil { + return *new(T), r.err + } return *r.value, r.err } -func (r Result[T]) GetSafe() T { +func (r Result[T]) GetUnsafe() T { if r.err != nil { panic(r.err) }