fixed Get and GetUnsafe methods for Result struct
This commit is contained in:
parent
6fcd709cd3
commit
3dfcee4ee4
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user