maybe

package
v0.3.0-8 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorNoValue = errors.New("cannot get value from failure Maybe")

Functions

This section is empty.

Types

type BindFunc

type BindFunc[A, B any] func(A) (B, error)

type Failure

type Failure[A any] struct {
	// contains filtered or unexported fields
}

func NewFailure

func NewFailure[A any](err error) *Failure[A]

func (*Failure[A]) Error

func (failure *Failure[A]) Error() error

func (*Failure[A]) Value

func (failure *Failure[A]) Value() A

func (*Failure[A]) ValueE

func (failure *Failure[A]) ValueE() (A, error)

type Maybe

type Maybe[A any] interface {
	Error() error
	ValueE() (A, error)
	Value() A
}

func Bind

func Bind[A, B any](a Maybe[A], bindFunc BindFunc[A, B]) Maybe[B]

func Result

func Result[A any](val A, err error) Maybe[A]

type Success

type Success[A any] struct {
	// contains filtered or unexported fields
}

func NewSuccess

func NewSuccess[A any](value A) *Success[A]

func (*Success[A]) Error

func (success *Success[A]) Error() error

func (*Success[A]) Value

func (success *Success[A]) Value() A

func (*Success[A]) ValueE

func (success *Success[A]) ValueE() (A, error)

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer wraps an io.Writer with the Maybe pattern to allow for fewer error checks when writing many strings in a row.

func NewWriter

func NewWriter(writer io.Writer) *Writer

NewWriter creates a new Writer wrapping the given io.Writer

func (*Writer) Error

func (maybeWriter *Writer) Error() error

func (*Writer) WriteString

func (maybeWriter *Writer) WriteString(str string)

Jump to

Keyboard shortcuts

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