Created
July 15, 2022 14:21
-
-
Save nwillc/fae895976665969acf9332e06557239c to your computer and use it in GitHub Desktop.
Go Error-Result pattern example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Result[T any] struct { | |
//... | |
} | |
// NewResult for a value. | |
func NewResult[T any](t T) *Result[T] {...} | |
// NewResultError creates a Result from a value, error tuple. | |
func NewResultError[T any](t T, err error) *Result[T] {...} | |
// NewError for an error. | |
func NewError[T any](err error) *Result[T] {...} | |
func (r *Result[T]) Ok() bool {...} | |
func (r *Result[T]) Error() error {...} | |
func (r *Result[T]) OrEmpty() T {...} | |
func Map[T, R any](t *Result[T], transform func(t T) *Result[R]) * Result[R] {...} | |
func MapError[T, R any](t *Result[T]) *genfuncs.Result[R] {...} | |
// See genfuncs for full implementation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment