tipe

package module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2023 License: Apache-2.0 Imports: 3 Imported by: 5

README

tipe

Generic Result and Option with tiny footprints for Go.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Result

type Result[T any] struct {
	// contains filtered or unexported fields
}

Result[T] is a type that can be used to return a value or an error. It is similar to Rust's Result<T, E> type. Result[T] occupies a fixed size of 3 words. For most common types, Result[T] needs no heap allocation.

func BindR added in v0.2.1

func BindR[T, U any](r Result[T], f func(T) Result[U]) Result[U]

func Err

func Err[T any](err error) Result[T]

Err returns a Result[T] that contains the given error.

func MakeR added in v0.2.1

func MakeR[T any](value T, err error) Result[T]

MakeR returns a Result[T] that contains the given value or error.

func MapR added in v0.2.1

func MapR[T, U any](r Result[T], f func(T) U) Result[U]

func Ok

func Ok[T any](value T) Result[T]

Ok returns a Result[T] that contains the given value.

func (Result[T]) Fill added in v0.2.0

func (r Result[T]) Fill(v T) Result[T]

Fill returns a new Result[T] that contains the given value.

func (Result[T]) FillErr added in v0.2.0

func (r Result[T]) FillErr(err error) Result[T]

FillErr returns a new Result[T] that contains the given error.

func (Result[T]) FillTuple added in v0.2.0

func (r Result[T]) FillTuple(v T, err error) Result[T]

FillTuple returns a new Result[T] that contains the given value or error.

func (Result[T]) IsErr

func (r Result[T]) IsErr() bool

IsErr returns true if the Result[T] contains an error.

func (Result[T]) IsOk

func (r Result[T]) IsOk() bool

IsOk returns true if the Result[T] contains a value.

func (Result[T]) String

func (r Result[T]) String() string

String returns a string representation of the Result[T].

func (Result[T]) Tuple

func (r Result[T]) Tuple() (T, error)

Tuple returns the value and error contained in the Result[T].

func (Result[T]) TupleBool

func (r Result[T]) TupleBool() (T, bool)

TupleBool returns the value and a boolean indicating whether the Result[T] is ok.

func (Result[T]) Unwrap

func (r Result[T]) Unwrap() T

Unwrap returns the value contained in the Result[T].

func (Result[T]) UnwrapErr

func (r Result[T]) UnwrapErr() error

UnwrapErr returns the error contained in the Result[T].

func (Result[T]) UnwrapOr

func (r Result[T]) UnwrapOr(or T) T

UnwrapOr returns the value contained in the Result[T]. If the Result[T] is an error, it returns the given value or.

func (Result[T]) Zero added in v0.2.0

func (r Result[T]) Zero() Result[T]

Zero returns a new Result[T] that contains the zero value of T.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL