union

package
v0.0.0-...-02bf512 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Four

type Four[T, U, V, W any] struct {
	// contains filtered or unexported fields
}

Four is a union of four values

func Of4T

func Of4T[TT, UU, VV, WW any](t TT) Four[TT, UU, VV, WW]

Of4T constructs a Four that holds a T

func Of4U

func Of4U[TT, UU, VV, WW any](u UU) Four[TT, UU, VV, WW]

Of4U constructs a Four that holds a U

func Of4V

func Of4V[TT, UU, VV, WW any](v VV) Four[TT, UU, VV, WW]

Of4V constructs a Four that holds a V

func Of4W

func Of4W[TT, UU, VV, WW any](w WW) Four[TT, UU, VV, WW]

Of4W constructs a Four that holds a W

func (*Four[TT, UU, VV, WW]) SetT

func (s *Four[TT, UU, VV, WW]) SetT(t TT)

SetT of Four

func (*Four[TT, UU, VV, WW]) SetU

func (s *Four[TT, UU, VV, WW]) SetU(u UU)

SetU of Four

func (*Four[TT, UU, VV, WW]) SetV

func (s *Four[TT, UU, VV, WW]) SetV(v VV)

SetV of Four

func (*Four[TT, UU, VV, WW]) SetW

func (s *Four[TT, UU, VV, WW]) SetW(w WW)

SetW of Four

func (Four[TT, UU, VV, WW]) String

func (s Four[TT, UU, VV, WW]) String() string

String is Stringer interface

func (Four[TT, UU, VV, WW]) T

func (s Four[TT, UU, VV, WW]) T() TT

T of Four Panics if which != T

func (Four[TT, UU, VV, WW]) U

func (s Four[TT, UU, VV, WW]) U() UU

U of Four Panics if which != U

func (Four[TT, UU, VV, WW]) V

func (s Four[TT, UU, VV, WW]) V() VV

V of Four Panics if which != V

func (Four[TT, UU, VV, WW]) W

func (s Four[TT, UU, VV, WW]) W() WW

W of Four Panics if which != W

func (Four[TT, UU, VV, WW]) Which

func (s Four[TT, UU, VV, WW]) Which() Which

Which of Four

type Maybe

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

Maybe is a wrapper around a single value that may or may not exist, as an alternative to a pointer or an Iter

func Empty

func Empty[TT any]() Maybe[TT]

Empty constructs an empty Maybe

func Of

func Of[TT any](t TT) Maybe[TT]

Of constructs a Maybe that holds a T. If t is nil, the Maybe is Empty, otherwise it is Present.

func (Maybe[T]) Empty

func (m Maybe[T]) Empty() bool

Empty returns true if Maybe does not contain a value

func (Maybe[T]) Get

func (m Maybe[T]) Get() T

Get returns the value of the Maybe, which panics if it is not present

func (Maybe[T]) OrElse

func (m Maybe[T]) OrElse(elseVal T) T

OrElse returns the value of the Maybe if present, or the else value provided if it is empty

func (Maybe[T]) OrError

func (m Maybe[T]) OrError(e error) (res T, err error)

OrError returns (value of the Maybe, nil) if present, or (zero value of T, error provided) if not present

func (Maybe[T]) Present

func (m Maybe[T]) Present() bool

Present returns true if Maybe contains a value

func (*Maybe[T]) Set

func (m *Maybe[T]) Set(newVal T)

Set overwrites the current value with newVal, and sets m as present unless the newVal is a nil pointer

func (*Maybe[T]) SetEmpty

func (m *Maybe[T]) SetEmpty()

SetEmpty overwrites the current value with the zero value, and sets m as empty

func (*Maybe[T]) SetOrError

func (m *Maybe[T]) SetOrError(newVal T) error

SetOrError sets the current value with val if empty, else returns an error if a present val has already been set

func (Maybe[T]) String

func (m Maybe[T]) String() string

String is the Stringer interface

type Result

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

Result is a variation of Two where the second value is predefined as an error

func OfError

func OfError[R any](err error) Result[R]

OfError constructs a Result that holds an error Panics if the error is nil

func OfResult

func OfResult[R any](r R) Result[R]

OfResult constructs a Result that holds an R

func OfResultError

func OfResultError[R any](r R, err error) Result[R]

OfResultError constructs a Result from a value of type R and an error Panics if the error is non-nil and R is not the zero value

func (Result[R]) Error

func (r Result[R]) Error() error

Error returns a nil error if there is a result, or a non-nil error if there is an error

func (Result[R]) Get

func (r Result[R]) Get() R

Get returns an R if there is a result, or zero value if there is an error

func (Result[R]) HasError

func (r Result[R]) HasError() bool

HasError is true if Result contains an error

func (Result[R]) HasResult

func (r Result[R]) HasResult() bool

HasResult is true if Result contains an R

func (Result[R]) String

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

String is the Stringer interface

type Three

type Three[T, U, V any] struct {
	// contains filtered or unexported fields
}

Three is a union of three values`

func Of3T

func Of3T[TT, UU, VV any](t TT) Three[TT, UU, VV]

Of3T constructs a Three that holds a T

func Of3U

func Of3U[TT, UU, VV any](u UU) Three[TT, UU, VV]

Of3U constructs a Three that holds a U

func Of3V

func Of3V[TT, UU, VV any](v VV) Three[TT, UU, VV]

Of3V constructs a Three that holds a V

func (*Three[TT, UU, VV]) SetT

func (s *Three[TT, UU, VV]) SetT(t TT)

SetT of Three

func (*Three[TT, UU, VV]) SetU

func (s *Three[TT, UU, VV]) SetU(u UU)

SetU of Three

func (*Three[TT, UU, VV]) SetV

func (s *Three[TT, UU, VV]) SetV(v VV)

SetV of Three

func (Three[TT, UU, VV]) String

func (s Three[TT, UU, VV]) String() string

String is Stringer interface

func (Three[TT, UU, VV]) T

func (s Three[TT, UU, VV]) T() TT

T of Three Panics if which != T

func (Three[TT, UU, VV]) U

func (s Three[TT, UU, VV]) U() UU

U of Three Panics if which != U

func (Three[TT, UU, VV]) V

func (s Three[TT, UU, VV]) V() VV

V of Three Panics if which != V

func (Three[TT, UU, VV]) Which

func (s Three[TT, UU, VV]) Which() Which

Which of Three

type Two

type Two[T, U any] struct {
	// contains filtered or unexported fields
}

Two is a union of two values

func Of2T

func Of2T[TT, UU any](t TT) Two[TT, UU]

Of2T constructs a Two that holds a T

func Of2U

func Of2U[TT, UU any](u UU) Two[TT, UU]

Of2U constructs a Two that holds a U

func (*Two[TT, UU]) SetT

func (s *Two[TT, UU]) SetT(t TT)

SetT of Two

func (*Two[TT, UU]) SetU

func (s *Two[TT, UU]) SetU(u UU)

SetU of Two

func (Two[TT, UU]) String

func (s Two[TT, UU]) String() string

String is Stringer interface

func (Two[TT, UU]) T

func (s Two[TT, UU]) T() TT

T of Two Panics if which != T

func (Two[TT, UU]) U

func (s Two[TT, UU]) U() UU

U of Two Panics if which != U

func (Two[TT, UU]) Which

func (s Two[TT, UU]) Which() Which

Which of Two

type Which

type Which uint

Which describes which member to return

const (
	T Which = iota
	U
	V
	W
)

func (Which) String

func (w Which) String() string

String is the Stringer interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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