either

package
v0.0.9-3 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AsyncError

type AsyncError Either[chan error]

AsyncError represents a value which could either be a synchronous error or an asynchronous error (sent through a channel). It wraps the more generic `Either` type specific for error channels.

func AsyncErr

func AsyncErr(errCh chan error) AsyncError

AsyncErr creates an AsyncError from an error channel. It wraps the error channel into the right field (conventionally associated with successful values in the Either pattern) of the Either type.

func SyncErr

func SyncErr(err error) AsyncError

SyncErr creates an AsyncError either from a synchronous error. It wraps the Error into the left field (conventionally associated with the error value in the Either pattern) of the Either type. It casts the result to the AsyncError type.

func (AsyncError) IsAsyncError

func (soaErr AsyncError) IsAsyncError() bool

IsAsyncError checks if the AsyncError represents an asynchronous error (sent through a channel).

func (AsyncError) IsSyncError

func (soaErr AsyncError) IsSyncError() bool

IsSyncError checks if the AsyncError represents a synchronous error.

func (AsyncError) SyncOrAsyncError

func (soaErr AsyncError) SyncOrAsyncError() (error, chan error)

SyncOrAsyncError decomposes the AsyncError into its components, returning a synchronous error and an error channel. If the AsyncError represents a synchronous error, the error channel will be nil and vice versa.

type Bytes

type Bytes = Either[[]byte]

type Either

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

Either represents a type that can hold either a value of type T or an error. It's commonly used in functional programming to encapsulate functions that might fail. This way, instead of returning a value and an error separately, both are combined into a single type.

func Error

func Error[T any](err error) Either[T]

Error creates an error Either value.

func NewEither

func NewEither[R any](right R, left error) Either[R]

func Success

func Success[T any](value T) Either[T]

Success creates a successful Either value.

func (Either[T]) IsError

func (m Either[T]) IsError() bool

IsError checks if the Either contains an error.

func (Either[T]) IsSuccess

func (m Either[T]) IsSuccess() bool

IsSuccess checks if the Either contains a success value.

func (Either[T]) ValueOrError

func (m Either[T]) ValueOrError() (T, error)

ValueOrError unpacks the Either value.

type SessionTrees added in v0.0.2

type SessionTrees = Either[[]relayer.SessionTree]

Jump to

Keyboard shortcuts

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