From a794c68cfe583ae8d7d51001563a78a0d14d1cea Mon Sep 17 00:00:00 2001 From: "Vladimir G." Date: Wed, 5 Feb 2025 15:34:14 -0500 Subject: [PATCH] Added wrappers --- Misc/Wrappers.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Misc/Wrappers.go diff --git a/Misc/Wrappers.go b/Misc/Wrappers.go new file mode 100644 index 0000000..27c914e --- /dev/null +++ b/Misc/Wrappers.go @@ -0,0 +1,31 @@ +package Misc + +type Result[T any] struct { + Value T + Err error +} + +func NewResult[T any](value T, err error) Result[T] { + return Result[T]{Value: value, Err: err} +} + +func (r Result[T]) IsOk() bool { + return r.Err == nil +} + +func (r Result[T]) IsErr() bool { + return r.Err != nil +} + +func (r Result[T]) Unwrap() (T, error) { + return r.Value, r.Err +} + +type Nullable[T any] struct { + Value T + IsNil bool +} + +func NewNullable[T any]() Nullable[T] { + return Nullable[T]{IsNil: true} +}