From b6d6daf299940115e8569c0552318cb30a3f15ef Mon Sep 17 00:00:00 2001 From: Vicente Olmedo Date: Mon, 21 Apr 2025 17:40:30 +0200 Subject: [PATCH] feat: a more convenient Result interface --- core/result/result.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core/result/result.go b/core/result/result.go index 5cae919..6d97776 100644 --- a/core/result/result.go +++ b/core/result/result.go @@ -8,18 +8,23 @@ import ( // Result is a golang compatible generic result type type Result[O any, X any] interface { - isResult(ok O, err X) + Ok() *O + Err() *X } type okResult[O any, X any] struct { value O } + +func (o *okResult[O, X]) Ok() *O { return &o.value } +func (o *okResult[O, X]) Err() *X { return nil } + type errResult[O any, X any] struct { value X } -func (o *okResult[O, X]) isResult(ok O, err X) {} -func (e *errResult[O, X]) isResult(ok O, err X) {} +func (e *errResult[O, X]) Ok() *O { return nil } +func (e *errResult[O, X]) Err() *X { return &e.value } // MatchResultR3 handles a result with functions returning 3 values func MatchResultR3[O any, X any, R0, R1, R2 any](