container

package
v0.0.0-...-ee163f1 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2022 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatePending = state(0)
	StateOk      = state(1)
)

Variables

View Source
var (
	ErrValue = errors.New("error: none or rejected value container")
)
View Source
var (
	UnitVal = Unit{}
)

Functions

func Must

func Must[T any, E error](value T, err E) T

Types

type Await

type Await[T any] interface {
	Await() T
}

type Error

type Error[E error] interface {
	Error() Option[E]
}

type Future

type Future[T any] interface {
	Poll() FutureResult[T]
	Await() T
}

func Async

func Async[T any](fn func() T) Future[T]

func Async2

func Async2[T any](fn func(chan<- T)) Future[T]

func AsyncUnit

func AsyncUnit(fn func()) Future[Unit]

func AsyncVal

func AsyncVal[T any](v T) Future[T]

type FutureResult

type FutureResult[T any] interface {
	Value[T]
	State() FutureState
}

type FutureState

type FutureState interface {
	Pending() bool
	Ok() bool
	String() string
}

type Option

type Option[T any] interface {
	Value[T]
	None()
	Or(T) T
	OrWith(Value[T]) T
	Map(Pipe[T, T]) Option[T]
	And(Option[T]) Option[T]
	Has() bool
}

func None

func None[T any]() Option[T]

func Some

func Some[T any](x T) Option[T]

func ToErrorOption

func ToErrorOption(x error) Option[error]

type Pipe

type Pipe[T any, I any] interface {
	Pipe(I) T
}

type Result

type Result[T any, E error] interface {
	Value[T]
	Error[E]
	Errored() bool
	Or(T) T
	OrWith(Value[T]) T
	MapErr(Pipe[T, E]) T
	Map(Pipe[T, T]) Result[T, E]
	Has() bool
	Raw() (*T, *E)
	Option() (Option[T], Option[E])
}

func Err

func Err[T any, E error](x E) Result[T, E]

func Ok

func Ok[T any, E error](x T) Result[T, E]

func Resuify

func Resuify[T any](x T, y error) Result[T, error]

func ToErr

func ToErr[T any, E error, U any](x Result[U, E]) Result[T, E]

type Unit

type Unit = struct{}

type Value

type Value[T any] interface {
	Value() T
}

Jump to

Keyboard shortcuts

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