base

package
v0.0.0-...-f630b54 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ENSURE_OBJECT_OK_STATE = "OK"
)

Variables

View Source
var UnitInvalidTypeError = NewError("Invalid Type")
View Source
var UnitInvalidUnitError = NewError("Invalid Unit")

Functions

func Assert

func Assert(cond bool)

Assert that condition is true if it's not panic with AssertionError

func AssertCustomError

func AssertCustomError(cond bool, err error)

Assert that condition is true if it's not panic with specified custom error

func AssertThat

func AssertThat() assertThat

func AssertThatTyped

func AssertThatTyped[T any]() assertThatTyped[T]

func AssertThatTyped2

func AssertThatTyped2[T1 any, T2 any]() assertThatTyped2[T1, T2]

func AssertThatTyped3

func AssertThatTyped3[T1 any, T2 any, T3 any]() assertThatTyped3[T1, T2, T3]

func AssertThatTyped4

func AssertThatTyped4[T1 any, T2 any, T3 any, T4 any]() assertThatTyped4[T1, T2, T3, T4]

func AssertThatTyped5

func AssertThatTyped5[T1 any, T2 any, T3 any, T4 any, T5 any]() assertThatTyped5[T1, T2, T3, T4, T5]

func CheckErr

func CheckErr(possibleError any) bool

Check if specified value is error Supports error, ErrorableGenericResultInterface, bool, int, uint If it gets other value it returns false

func ComplexNonInclusiveRange

func ComplexNonInclusiveRange(start int, end int, step int) []int

Range function returns an array to be used with for _, i := range ComplexNonInclusiveRange(end)

func ComplexRange

func ComplexRange(start int, end int, step int) []int

Range function returns an array to be used with for _, i := range ComplexRange(end)

func ConvertToAnyArray

func ConvertToAnyArray[T any](array []T) []any

Convert specified array of type T to array of type any

func Dump

func Dump(vs ...any)

Dump variable to console output

func EnsureType

func EnsureType[T any](value any) T

Ensure that value is of type T or panic

func EnsureTypeBool

func EnsureTypeBool[T any](value any) bool

Ensure that value is of type T and return bool

func ExecuteAndPassthrough

func ExecuteAndPassthrough(f func([]any) []any, values ...any) []any

Execute specified function and pass through all values

func ExecuteInDebugMode

func ExecuteInDebugMode(f func())

Execute specified function only in Debug Mode

func ExpandError

func ExpandError(err error) error

Expand provided error adding stacktrace

func Explode

func Explode(array []any, values ...*any)

Explode array into provided references to variables

func ExplodeTyped

func ExplodeTyped[T any](array []T, values ...*T)

Explode array into provided references to variables with specified type T

func GetDebugMode

func GetDebugMode() bool

Get Current State of Debug Mode

func GetMaxForType

func GetMaxForType[T NumericType]() T

GetMaxForType Get Max Value for specified numeric type

func GetMinForType

func GetMinForType[T NumericType]() T

GetMinForType Get Min Value for specified numeric type

func IKnowThatThisPackageIsNotUsed

func IKnowThatThisPackageIsNotUsed(x ...any)

Ignore package imported and not used

func IKnowThatThisVariableIsNotUsed

func IKnowThatThisVariableIsNotUsed(x ...any)

Ignore variable declared and not used

func IsError

func IsError(err error) bool

Check if specified value is error or it's nil or NilError

func IsErrorEqual

func IsErrorEqual(err1 error, err2 error) bool

Check if 2 errors are equal

func MakeGenerator

func MakeGenerator[T any](
	abortChannel <-chan struct{},
	generatorFunc func(chan T) bool,
) <-chan T

Make Generator abortChannel is used to stop generator generatorFunc is generator function that is called every iteration like next. Have to have parameter for channel for writing values and returning bool if it should stop (false) or continue (true) Note that this generator is executed in goroutine

func MakeUnit

func MakeUnit[T any](unitName string) func(T) UnitValue[T]

Make function that will return unit This is factory of method to make function for specific unit

func NewError

func NewError(msg string) error

Make New Error

func NormalizeUnit

func NormalizeUnit[T any](unitName string) func(any) Result[UnitValue[T]]

Make function that will normalize to unit type

func NotImplemented

func NotImplemented()

Note that something is not yet implement This function panics with NotImplementedError

func NotSupported

func NotSupported()

Note that something is not supported This function panics with NotSupportedError

func NullValue

func NullValue[T any]() T

Null value

func PackToArray

func PackToArray(values ...any) []any

Pack values provided as arguments to array

func PackagesUsedInDebugging

func PackagesUsedInDebugging(x ...any)

Ignore package imported and not used for debugging packages

func PanicIfError

func PanicIfError(err error)

Panic if value provided is error

func PanicIfErrorFromOutput

func PanicIfErrorFromOutput(returns ...any)

Panic if Error from specified function output has error

func Pipe

func Pipe(initialArgument any, functions ...any) any

Pipeline Function Call like Pipe(1, f1, f2, f3) should work similiarly to 1 |> f1 |> f2 |> f3

func PipeTyped

func PipeTyped[VT any](
	initialArgument VT,
	functions ...func(VT) VT,
) VT

Pipeline function This variant is fully typed. Note this function don't let you change type of pipeline value at any point

func PipeTypedArgReturn

func PipeTypedArgReturn[IAT any, RT any](initialArgument IAT, functions ...any) RT

Pipeline Function This variant is have enforced return type and initialArgument

func PipeTypedReturn

func PipeTypedReturn[RT any](initialArgument any, functions ...any) RT

Pipeline Function This variant is have enforced return type

func PossiblyUsingThis

func PossiblyUsingThis(x ...any)

Ignore package imported and not used

func PromiseAll

func PromiseAll(functions ...any) ([]any, []error)

Run all promises and wait for their results

func Range

func Range(end int) []int

Range function returns an array to be used with for i := range Range(end) This index will start from 0 to end

func RangeNonInclusive

func RangeNonInclusive(end int) []int

Range function returns an array to be used with for i := range RangeNonInclusive(end) This index will start from 0 to end - 1

func SetDebugMode

func SetDebugMode(mode bool)

Set Debug Mode

func StartEndNonInclusiveRange

func StartEndNonInclusiveRange(start int, end int) []int

Range function returns an array to be used with for _, i := range StartEndNonInclusiveRange(end)

func StartEndRange

func StartEndRange(start int, end int) []int

Range function returns an array to be used with for _, i := range StartEndRange(end)

func Ternary

func Ternary[V any](condition bool, ifTrue V, ifFalse V) V

Ternary Operation You can see this function as something like condition ? ifTrue : ifFalse

func TernaryNull

func TernaryNull[V any](value V, ifNullValue V) V

Ternary that checks if value provided is nil if it's nil it uses second argument as return You can see this function as something like value ?? ifNullValue

func TernaryNullable

func TernaryNullable[V any](value Nullable[V], ifNullValue V) V

Ternary that checks if value provided is not null according to NullableType if it's null it uses second argument as return You can see this function as something like value ?? ifNullValue but a bit more complicated because it's checks Value for OptionType (Nullable) if it is something or nothing

func TernaryResult

func TernaryResult[V any](result Result[V], ifOk V, ifErr V) V

Ternary that checks if result is ok or err and returns specified value for this condition

func ToPtr

func ToPtr[T any](value T) *T

Return a pointer copy of value

func Unreachable

func Unreachable()

Note that something is not reachable This function panics with UnreachableError

func WithContext

func WithContext[T any](
	ctx ContextManagerInterface,
	f func(ctx ContextManagerInterface) T,
) T

Do something with context from context manager object Before executing function specified it calls Enter and Exit is called on defer

func WithGoContext

func WithGoContext[T any](
	ctx GoContextManagerInterface,
	f func(ctx GoContextManagerInterface) T,
) T

Do something with context from context manager object Before executing function specified it calls Close on defer

func Yield

func Yield[T any](ch chan<- T, value T)

Yield in Generator Add Value to Channel

Types

type AnyFloat

type AnyFloat interface {
	~float32 | ~float64
}

type AnyInt

type AnyInt interface {
	~int8 | ~int16 | ~int32 | ~int64 | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~int | ~uint
}

type AssertableBoolInterface

type AssertableBoolInterface interface {
	// Method that checks if object is valid
	// This method should return bool if object is valid
	AssertBool() bool
}

type AssertableInterface

type AssertableInterface interface {
	// Method that checks if object is valid
	// This method should use Assert method inside or AssertCustomError method
	Assert()
}

Assertable Interface Object

type BroadcastChannel

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

Broadcast Channel Structure

func MakeBroadcastChannel

func MakeBroadcastChannel[T any]() BroadcastChannel[T]

Make Broadcast Channel

func (BroadcastChannel[T]) Broadcast

func (bc BroadcastChannel[T]) Broadcast(message T)

Broadcast Message to all subchannels

func (BroadcastChannel[T]) Subscribe

func (bc BroadcastChannel[T]) Subscribe(id string) chan T

Subscribe to Broadcast Channel by getting your own subchannel

func (BroadcastChannel[T]) Unsubscribe

func (bc BroadcastChannel[T]) Unsubscribe(id string)

Unsubscribe from Broadcast Channel by deleting the subchannel

type ContextManagerInterface

type ContextManagerInterface interface {
	// Enter into Context
	Enter()
	// Exit from Context
	Exit()
}

Context Manager Interface with methods on entering and exiting context This interface could be on pointer type or struct itself based if it have to manipulate data on struct

type DefaultableInterface

type DefaultableInterface[T any] interface {
	// Get Default Value
	GetDefault() T
}

Defaultable Interface

type EnsuredObject

type EnsuredObject interface {
	// Function for checking if Object is according to implementation
	Dev() Result[string]
}

type ErrorableGenericResultInterface

type ErrorableGenericResultInterface interface {
	// Check if Object has error
	IsError() bool
	// Get Error if Object has error or nil if not
	GetError() error
}

Errorable Generic Result Interface Object This interface is meant to be used for checking if Result[T] has error or similiar object to Result[T] without option to check for underlying type of Result

type Exception

type Exception struct {
	Message  string
	Category ExceptionCategory
}

func (Exception) Error

func (e Exception) Error() string

func (Exception) GoString

func (e Exception) GoString() string

func (Exception) GuardInit

func (e Exception) GuardInit()

func (*Exception) Init

func (e *Exception) Init(category ExceptionCategory, msg string)

func (Exception) String

func (e Exception) String() string

type ExceptionCategory

type ExceptionCategory string

type ExtendedException

type ExtendedException struct {
	Exception
	Stacktrace string
	Notes      []string
}

func (*ExtendedException) AddNote

func (e *ExtendedException) AddNote(note string)

func (ExtendedException) GoString

func (e ExtendedException) GoString() string

func (ExtendedException) GuardInit

func (e ExtendedException) GuardInit()

func (*ExtendedException) Init

func (e *ExtendedException) Init(category ExceptionCategory, msg string)

func (ExtendedException) String

func (e ExtendedException) String() string

type ExtendedUnwrappableInterface

type ExtendedUnwrappableInterface[V any] interface {
	// Unwrap but if error occurs run specified function f instead of panic
	// Return underlying value
	UnwrapOrErr(f func(UnwrappableInterface[V])) V
	// Unwraps as result type for if error checks and run specified function f
	// instead of panic
	// Return result of underlying value (having err if it's found)
	UnwrapAsResultOrErr(f func(UnwrappableInterface[V])) Result[V]
}

Unwrappable Interface Extension This functions should be implemented by any object that want to implement Unwrappable Interface This functions are based on UnwrappableInterface itself being a problem for type checks for some reason

type FeatureFlags

type FeatureFlags struct {
	IntFlags    map[string]int64
	UIntFlags   map[string]uint64
	StringFlags map[string]string
	BoolFlags   map[string]bool
	FloatFlags  map[string]float64
	AnyFlags    map[string]any
}

func GetFeatureFlags

func GetFeatureFlags() *FeatureFlags

func MakeFeatureFlags

func MakeFeatureFlags() *FeatureFlags

func (FeatureFlags) Dev

func (f FeatureFlags) Dev() Result[string]

func (*FeatureFlags) GetAnyFlag

func (f *FeatureFlags) GetAnyFlag(key string) any

func (*FeatureFlags) GetBoolFlag

func (f *FeatureFlags) GetBoolFlag(key string) bool

func (*FeatureFlags) GetDefault

func (f *FeatureFlags) GetDefault() *FeatureFlags

func (*FeatureFlags) GetFloatFlag

func (f *FeatureFlags) GetFloatFlag(key string) float64

func (*FeatureFlags) GetIntFlag

func (f *FeatureFlags) GetIntFlag(key string) int64

func (*FeatureFlags) GetStringFlag

func (f *FeatureFlags) GetStringFlag(key string) string

func (*FeatureFlags) GetUintFlag

func (f *FeatureFlags) GetUintFlag(key string) uint64

func (*FeatureFlags) SetAnyFlag

func (f *FeatureFlags) SetAnyFlag(key string, value any)

func (*FeatureFlags) SetBoolFlag

func (f *FeatureFlags) SetBoolFlag(key string, value bool)

func (*FeatureFlags) SetFloatFlag

func (f *FeatureFlags) SetFloatFlag(key string, value float64)

func (*FeatureFlags) SetIntFlag

func (f *FeatureFlags) SetIntFlag(key string, value int64)

func (*FeatureFlags) SetStringFlag

func (f *FeatureFlags) SetStringFlag(key string, value string)

func (*FeatureFlags) SetUintFlag

func (f *FeatureFlags) SetUintFlag(key string, value uint64)

type GoContextManagerInterface

type GoContextManagerInterface interface {
	// Close on Context Leave
	Close()
}

Context Manager Interface with methods on entering and exiting context This interface is based on close method that is made in some go objects for use in defer This interface could be on pointer type or struct itself based if it have to manipulate data on struct

type GuardedObjectInterface

type GuardedObjectInterface interface {
	// Initialize method for Guarded Object
	// This method is meant to be used in init method of module and contain only assert that check for example if object
	// is compatible with some interfaces or some version of go or something else and things like that for objects logic
	// to be correct
	GuardInit()
}

Guarded Object Interface Guarded Object is meant to be object that has some guards that need to be the case or this object is not valid at all

type Nullable

type Nullable[T any] struct {
	Data  T
	Valid bool
}

Nullable represents data that also can be NULL Implements UnwrappableInterface

func None

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

Make Nullable type with null value

func Null

func Null[T any]() Nullable[T]

Null Create a Nullable that is NULL with type

func NullableValue

func NullableValue[T any](value T) Nullable[T]

Value Create a Nullable from a value

func NullableValueFromPointer

func NullableValueFromPointer[T any](value *T) Nullable[T]

ValueFromPointer Create a Nullable from a pointer

func Some

func Some[T any](value T) Nullable[T]

Make Nullable type with correct value

func (Nullable[T]) AndThen

func (n Nullable[T]) AndThen(fn func(T) any) any

Run function fn when value is not NULL

func (Nullable[T]) Equal

func (n Nullable[T]) Equal(other Nullable[T]) bool

Equal Check if this Nullable is equal to another Nullable

func (Nullable[T]) ExactEqual

func (n Nullable[T]) ExactEqual(other Nullable[T]) bool

ExactEqual Check if this Nullable is exact equal to another Nullable, never using intern Equal method to check equality

func (Nullable[T]) Expect

func (n Nullable[T]) Expect(err any)

Expect correct value if error is found panic with specified message

func (Nullable[T]) ExpectErr

func (n Nullable[T]) ExpectErr(err any)

Expect error value if error is not found panic with specified message

func (Nullable[T]) GetError

func (n Nullable[T]) GetError() error

Get Error if Object has error or nil if not

func (Nullable[T]) GoString

func (n Nullable[T]) GoString() string

Get Go String

func (Nullable[T]) IsError

func (n Nullable[T]) IsError() bool

Check if Object has error

func (Nullable[T]) IsZero

func (n Nullable[T]) IsZero() bool

func (Nullable[T]) String

func (n Nullable[T]) String() string

String Convert value to string

func (Nullable[T]) Unwrap

func (n Nullable[T]) Unwrap() T

Get underlying value or panic if error

func (Nullable[T]) UnwrapAsResultOrErr

func (n Nullable[T]) UnwrapAsResultOrErr(f func(Nullable[T])) Result[T]

Unwraps as result type for if error checks and run specified function f instead of panic Return result of underlying value (having err if it's found)

func (Nullable[T]) UnwrapErr

func (n Nullable[T]) UnwrapErr() error

Get underlying error or panic if correct value

func (Nullable[T]) UnwrapOr

func (n Nullable[T]) UnwrapOr(defaultVal T) T

Get underlying value or return default value if error is found

func (Nullable[T]) UnwrapOrErr

func (n Nullable[T]) UnwrapOrErr(f func(Nullable[T])) T

Unwrap but if error occurs run specified function f instead of panic Return result of underlying value (having err if it's found)

func (Nullable[T]) UnwrapWithErr

func (n Nullable[T]) UnwrapWithErr() (T, error)

Unwrap value and error separately (Result -> Go normal returns)

func (Nullable[T]) Value

func (n Nullable[T]) Value() (driver.Value, error)

Get underlying value

func (Nullable[T]) ValueOrZero

func (n Nullable[T]) ValueOrZero() T

ValueOrZero Get Value, or default zero value if it is NULL

type NumericType

type NumericType interface {
	~int8 | ~int16 | ~int32 | ~int64 | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64 | ~int | ~uint
}

type Observable

type Observable[T any] struct {
	Value       T
	GetHandlers []func(Observable[T])
	SetHandlers []func(Observable[T])
}

Observable Object

var DebugMode Observable[bool] = MakeObservable[bool](false)

DebugMode Variable

func MakeObservable

func MakeObservable[T any](value T) Observable[T]

Make New Observable

func (*Observable[T]) AddGetHandler

func (o *Observable[T]) AddGetHandler(handler func(Observable[T]))

Add Get Handler Get Handler is called when GetValue is called

func (*Observable[T]) AddSetHandler

func (o *Observable[T]) AddSetHandler(handler func(Observable[T]))

Add Set Handler Set Handler is called when SetValue is called

func (*Observable[T]) GetValue

func (o *Observable[T]) GetValue() T

Get Value of Observable

func (*Observable[T]) NotifyGet

func (o *Observable[T]) NotifyGet()

Notify Get Handlers

func (*Observable[T]) NotifySet

func (o *Observable[T]) NotifySet()

Notify Set Handlers

func (*Observable[T]) SetValue

func (o *Observable[T]) SetValue(value T)

Set Value of Observable

type Pipeline

type Pipeline struct {
	Function any
	Data     []any
}

Pipeline object You can think of this as promise like construct without any asynchronity or like |> operator

func MakePipeline

func MakePipeline(value any) Pipeline

Make New Pipeline from specified function

func MakePipelineFromPointer

func MakePipelineFromPointer(value *any) Pipeline

Make New Pipeline from specified pointer to function

func (*Pipeline) Call

func (p *Pipeline) Call(args ...any) *Pipeline

Run Pipeline and chain next operations (Same as Evaluate)

func (*Pipeline) Catch

func (p *Pipeline) Catch(f any) *Pipeline

Do something if Pipeline has error

func (*Pipeline) Evaluate

func (p *Pipeline) Evaluate(args ...any) *Pipeline

Run Pipeline and chain next operations

func (*Pipeline) EvaluateOnData

func (p *Pipeline) EvaluateOnData() *Pipeline

Run Pipeline with arguments as data inside the pipeline and chain next operations

func (*Pipeline) Finally

func (p *Pipeline) Finally(f any) *Pipeline

Do something no matter if Pipeline has error or no

func (*Pipeline) GetError

func (p *Pipeline) GetError() error

Get Error if Pipeline has error otherwise return nil

func (*Pipeline) GetErrorSpecial

func (p *Pipeline) GetErrorSpecial() error

Get Error if it's nil return NilErrorErr Structure

func (*Pipeline) IsError

func (p *Pipeline) IsError() bool

Check if Pipeline got error value in the data

func (*Pipeline) Run

func (p *Pipeline) Run(args ...any) []any

Run Pipeline and Get underlying data

func (*Pipeline) Then

func (p *Pipeline) Then(f any) *Pipeline

Do something if Pipeline doesn't have any error

func (*Pipeline) Value

func (p *Pipeline) Value() []any

Get underlying data of Pipeline

func (*Pipeline) ValueRef

func (p *Pipeline) ValueRef(returns ...*any)

Get underlying data of Pipeline inside variables specified as args

type PipelineArray

type PipelineArray struct {
	Pipelines []Pipeline
}

func NewPipelineArray

func NewPipelineArray(pipelines ...Pipeline) PipelineArray

Make new pipeline array

func (PipelineArray) All

func (p PipelineArray) All(args ...[]any) Pipeline

Run All Pipelines inside array If any pipeline returns an error, the error is returned and execution of pipelines is stopped

func (PipelineArray) Any

func (p PipelineArray) Any(args ...[]any) Pipeline

Run Pipelines inside array and stop execution when first pipeline without error will be found

func (PipelineArray) RunAll

func (p PipelineArray) RunAll(args ...[]any) []any

Run All Pipelines inside array

type PipelineArrayAnyError

type PipelineArrayAnyError struct {
}

func (PipelineArrayAnyError) Error

func (PipelineArrayAnyError) Error() string

type Promise

type Promise struct {
	Function any
	Result   any
	Error    error
	// contains filtered or unexported fields
}

func MakePromise

func MakePromise(f any) Promise

Make Promise

func MakePromisePointer

func MakePromisePointer(f any) *Promise

Make Promise Pointer

func (*Promise) Call

func (p *Promise) Call(args ...any) Pipeline

Call Promise

func (*Promise) Wait

func (p *Promise) Wait()

Wait until Promise is finished

type Result

type Result[T any] struct {
	DataValue  T
	ErrorValue error
}

func CheckAllResults

func CheckAllResults[T any](results ...Result[T]) Result[T]

Check All Results and return first error or last ok value

func ConvertToResult

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

Convert basic go function return value to result

func ConvertToResultMultiple

func ConvertToResultMultiple(args ...any) Result[any]

Convert multiple return value function return in go style to result

func EnsureObjectImplementsInterface

func EnsureObjectImplementsInterface[OT any, IT any](self OT) Result[string]

Ensure that specified object implements provided interface OT - Object Type IT - Interface Type self - Object Returns Result type

func EnsureTypeResult

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

Ensure that value is of type T and return Result

func Err

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

Make Result with error value

func ErrWithValue

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

Make Result with ok and error values

func MakeErrorResult

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

Make Error Result

func MakeErrorResultWithValue

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

Make Error Result with additional data

func MakeOkResult

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

Make Ok Result

func MakeResult

func MakeResult[T any]() Result[T]

Make Result

func Ok

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

Make Result with ok value

func PanicToError

func PanicToError[T any](f func() T) Result[T]

Change block that could panic into Result with error as value Note this function only catches panic errors and strings

func (Result[T]) AndThen

func (r Result[T]) AndThen(fn func(T) any) any

Run function fn when Result is Ok

func (*Result[T]) Error

func (r *Result[T]) Error(err error) Result[T]

Error Result

func (Result[T]) Expect

func (r Result[T]) Expect(err any)

Expect correct value if error is found panic with specified message

func (Result[T]) ExpectErr

func (r Result[T]) ExpectErr(err any)

Expect error value if error is not found panic with specified message

func (Result[T]) GetError

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

If result has error get error otherwise return nil

func (Result[T]) GoString

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

Get Go String

func (Result[T]) IsError

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

Check if Result has error

func (*Result[T]) Ok

func (r *Result[T]) Ok(value T) Result[T]

Ok Result

func (Result[T]) String

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

String Convert value to string

func (Result[T]) ToPointer

func (r Result[T]) ToPointer() *Result[T]

Get Pointer of Result

func (*Result[T]) ToResult

func (r *Result[T]) ToResult() Result[T]

Get Result from Pointer

func (Result[T]) Unwrap

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

Get underlying value or panic if error

func (Result[T]) UnwrapAsResultOrErr

func (r Result[T]) UnwrapAsResultOrErr(f func(Result[T])) Result[T]

Unwraps as result type for if error checks and run specified function f instead of panic Return result of underlying value (having err if it's found)

func (Result[T]) UnwrapErr

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

Get underlying error or panic if correct value

func (Result[T]) UnwrapOr

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

Get underlying value or return default value if error is found

func (Result[T]) UnwrapOrErr

func (r Result[T]) UnwrapOrErr(f func(Result[T])) T

Unwrap but if error occurs run specified function f instead of panic Return result of underlying value (having err if it's found)

func (Result[T]) UnwrapWithErr

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

Unwrap value and error separately (Result -> Go normal returns)

type SubCategoryExtendedException

type SubCategoryExtendedException struct {
	ExtendedException
}

func MakeException

func MakeException(category ExceptionCategory, subcategory ExceptionCategory, msg string) SubCategoryExtendedException

func (SubCategoryExtendedException) GoString

func (e SubCategoryExtendedException) GoString() string

func (SubCategoryExtendedException) GuardInit

func (e SubCategoryExtendedException) GuardInit()

func (*SubCategoryExtendedException) Init

func (e *SubCategoryExtendedException) Init(category ExceptionCategory, subcategory ExceptionCategory, msg string)

func (SubCategoryExtendedException) String

type SwitchResult

type SwitchResult[SV any, V any] struct {
	// Value to Switch On
	SwitchValue SV
	// Result Value
	Value V
	// Is Switch Found
	SwitchFound bool
}

Switch Result Type

func Switch

func Switch[SV any, V any](value SV) *SwitchResult[SV, V]

Switch Statement based on provided value

func (*SwitchResult[SV, V]) Case

func (s *SwitchResult[SV, V]) Case(f func(SV) (V, bool)) *SwitchResult[SV, V]

Case for Switch specified function have to take switch value and return tuple of value and bool if it was found in that case

func (*SwitchResult[SV, V]) Default

func (s *SwitchResult[SV, V]) Default(f func(SV) V) *SwitchResult[SV, V]

Default Case for Switch specified function have to take switch value and return value

type ThreadSafeObject

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

Thread Safe Object that builds arround some value and make methods to set it and get it in thread safe way

func MakeThreadSafeObject

func MakeThreadSafeObject[T any](obj T) ThreadSafeObject[T]

func (*ThreadSafeObject[T]) Get

func (tso *ThreadSafeObject[T]) Get() T

Get underlying object value

func (*ThreadSafeObject[T]) Set

func (tso *ThreadSafeObject[T]) Set(newObj T)

Set underlying object to new value

type Transaction

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

Transaction implements a Saga pattern

func NewTransaction

func NewTransaction[T any]() *Transaction[T]

NewTransaction instanciate a new transaction.

func (*Transaction[T]) Process

func (t *Transaction[T]) Process(state T) (T, error)

Process runs the Transaction steps and rollbacks in case of errors.

func (*Transaction[T]) Then

func (t *Transaction[T]) Then(exec func(T) (T, error), onRollback func(T) T) *Transaction[T]

Then adds a step to the chain of callbacks. It returns the same Transaction.

type Tuple2

type Tuple2[T1 any, T2 any] struct {
	V1 T1
	V2 T2
}

type Tuple3

type Tuple3[T1 any, T2 any, T3 any] struct {
	V1 T1
	V2 T2
	V3 T3
}

type Tuple4

type Tuple4[T1 any, T2 any, T3 any, T4 any] struct {
	V1 T1
	V2 T2
	V3 T3
	V4 T4
}

type Tuple5

type Tuple5[T1 any, T2 any, T3 any, T4 any, T5 any] struct {
	V1 T1
	V2 T2
	V3 T3
	V4 T4
	V5 T5
}

type Union

type Union[T1 any, T2 any] struct {
	Data Tuple2[T1, T2]
	Type uint8
}

func (Union[T1, T2]) Get

func (u Union[T1, T2]) Get() (uint8, any)

func (Union[T1, T2]) GetT1

func (u Union[T1, T2]) GetT1() T1

func (Union[T1, T2]) GetT2

func (u Union[T1, T2]) GetT2() T2

func (Union[T1, T2]) GuardInit

func (u Union[T1, T2]) GuardInit()

func (*Union[T1, T2]) Set

func (u *Union[T1, T2]) Set(t uint8, v any)

func (*Union[T1, T2]) SetT1

func (u *Union[T1, T2]) SetT1(v T1)

func (*Union[T1, T2]) SetT2

func (u *Union[T1, T2]) SetT2(v T2)

type UnionInterface

type UnionInterface interface {
	Get() (uint8, any)
	Set(uint8, any)
}

type UnionTypeConstraint

type UnionTypeConstraint[T1 any, T2 any] interface {
	*T1 | *T2
}

type UnitValue

type UnitValue[T any] struct {
	Value    T
	UnitName string
}

Note that some value has specific unit like seconds

func MakeEmptyUnit

func MakeEmptyUnit[T any](unitName string) UnitValue[T]

Make Empty Unit

func Unit

func Unit[T any](value T, unitName string) UnitValue[T]

Note that some value is in specific unit like seconds

func (UnitValue[T]) GetUnitName

func (u UnitValue[T]) GetUnitName() string

Get Unit Name

func (UnitValue[T]) GetValue

func (u UnitValue[T]) GetValue() T

Get Value

func (UnitValue[T]) GoString

func (u UnitValue[T]) GoString() string

Get Go String

func (UnitValue[T]) String

func (u UnitValue[T]) String() string

String Convert value to string

type UnwrappableInterface

type UnwrappableInterface[V any] interface {
	// Get underlying value or panic if error
	Unwrap() V
	// Get underlying error or panic if correct value
	UnwrapErr() error
	// Get underlying value or return default value if error is found
	UnwrapOr(defaultVal V) V
	// Unwrap value and error separately (Result -> Go normal returns)
	UnwrapWithErr() (V, error)
	// Expect correct value if error is found panic with specified message
	Expect(err any)
	// Expect error value if error is not found panic with specified message
	ExpectErr(err any)
}

Unwrappable Interface Object

Jump to

Keyboard shortcuts

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