Skip to content

Commit

Permalink
Added wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir2217 committed Feb 5, 2025
1 parent 8d97ccd commit a794c68
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Misc/Wrappers.go
Original file line number Diff line number Diff line change
@@ -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}
}

0 comments on commit a794c68

Please sign in to comment.